1

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

  • related : https://stackoverflow.com/questions/2283566/how-can-i-round-a-number-in-javascript-tofixed-returns-a-string – Pac0 May 12 '20 at 06: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`); – Yosef Tukachinsky May 12 '20 at 06: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. – Wiimm May 13 '20 at 14:53

0 Answers0