I have two negative value -0.245
and -9.085
. I want make them to 2 decimal places. I am using JavaScript function toFixed()
but getting some weird result.
Please help me to under stand the logic behind the first example being rounded "down" but the second being rounded "up"
//Examples 1. result coming as expected
var num = -0.245
var n = num.toFixed(2); //-0.24
console.log(n);
//Examples 2. result should be -9.08
num = -9.085
n = num.toFixed(2); //-9.09
console.log(n);