Motion - 7 months ago 32

jQuery Question

I have 2 number that I use Math.round to round it,for example I want if my number is 900.20 it rounded to 900.00 and if 12.80 it rounded to 13.

I use Math.round but 900.20 rounded to 910.00 but 12.8 rounded to 13 correctly.

`var num1=900.20;`

var num2=12.80;

var result1= Math.round(num1.toFixed(2));

var result2= Math.round(num2.toFixed(2));

Answer

Why you are using `.toFixed()`

function ?
Just use `Math.round()`

function and it will work. You don't need to convert it to string.