3

Is there some kind of bug in the toFixed function in Javascript ?

6.075.toFixed(2) // = 6.08 (correct!)
8.075.toFixed(2) // = 8.07 (wrong!) should be 8.08 right ??

Am I missing something ?

Why is this, what's going on ? How can I get 8.075 to round correctly up to 8.08 ?

Thanks!

VLAZ
  • 26,331
  • 9
  • 49
  • 67
mdirect
  • 51
  • 3
  • It does the rounding too, as it says on the tin: "rounding to nearest integer" - https://www.w3schools.com/jsref/jsref_tofixed.asp – Nicolae Maties Jan 20 '21 at 13:06
  • Feels like floating point error. I'll read the duplicate target carefully to see if it's already covered. – user202729 Jan 20 '21 at 13:47
  • https://stackoverflow.com/questions/5490687/broken-tofixed-implementation/37751946 has a (in my opinion) better answer. – user202729 Jan 20 '21 at 13:59

0 Answers0