How to get following inputs to bellow outputs
Input
1.0789 10.350 1.7777
Output
1.07 10.35 1.77
Shift the decimal of the given value to the given decimal point by multiplying 10^n. Take the floor of the number and divide the number by 10^n. The final value is the truncated value.
Rounding a decimal number to two decimal places is the same as rounding it to the hundredths place, which is the second place to the right of the decimal point. For example, 2.83620364 can be round to two decimal places as 2.84, and 0.7035 can be round to two decimal places as 0.70.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With