29

How to get following inputs to bellow outputs

Input

1.0789
10.350
1.7777

Output

1.07
10.35
1.77
GG.
  • 19,404
  • 12
  • 77
  • 125
I don't know
  • 569
  • 1
  • 7
  • 15

2 Answers2

73

Use Math.floor to round the decimal places under the current value.

Reference

Example

Math.floor(1.0789 * 100) / 100

Working Fiddle

console.log(Math.floor(1.0789 * 100) / 100);
console.log(Math.floor(10.350 * 100) / 100);
console.log(Math.floor(1.7777 * 100) / 100);
console.log(Math.floor(12.34 * 100) / 100);
Nitheesh
  • 17,055
  • 2
  • 18
  • 45
0

you have several methods for do this

  1. Use Math.round(num * 100) / 100
  2. Use Math.ceil(num * 100)/100;
ADH - THE TECHIE GUY
  • 3,602
  • 2
  • 27
  • 53