Rounding a floating number is easy as pie. There are many ways to do that. Let’s see the example.
Using .toFixed
// toFixed(3) var num = 58.8963; var result = num.toFixed(3); // result equal to 58.896 // toFixed(2) when the number has no decimal places num = 70; result = num.toFixed(3); // result equal to 70.000
Error in Floating Point :
num = 162.295
num *= 100 // 16229.499999999998
num = Math.round(num) // 16229
num /= 100 // 162.29
As we see at second point, num will return exact value. So beware to use it for calculation.
(Source: http)