1

(1.125).toFixed(2) = '1.13' but (1.025).toFixed(2) = '1.02' Which should be 1.03 in JS.

3
  • related : stackoverflow.com/questions/2283566/… Commented May 12, 2020 at 6:46
  • it's just lost some super small amount during the calculation, and appear to be less then .5, so round down. You can ether add some small amount ((num+0.000001).toFixed(2)) or do the rounding yourself (Math.round(num*100)/100); Commented May 12, 2020 at 6:57
  • 1
    The number 1.025 dost not exists and is rounded to the nearest possible number: (1.025).toPrecision(18); // 1.02499999999999991. And for this number rounding to 1.02 is correct. Commented May 13, 2020 at 14:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.