JavaScript num.toFixed() method

40 views Asked by At

I have question regarding JavaScript toFixed(). I am facing some difference in rounding,

let num1=1.635;
let num2=10.635;

console.log(num1.toFixed(2)); // I am getting the output as 1.64 which is correct.
console.log(num2.toFixed(2)); // but now I am getting 10.63 instead of 10.64.

can anyone explain about this behavior of the above code and suggest how to overcome this?

0

There are 0 answers