-3

I have run the following code in several browser console and I had the same result everytime :

>>> (17.06 * 100) === 1706
false
>>> (6.06 * 100) === 606
true

This is not logic.

Where does the problem come from ?

Marc Dupuis
  • 523
  • 2
  • 5
  • 14

1 Answers1

0

This is a floating point rounding error.

In JavaScript, 17.06 * 100 !== 1706, it's 1705.9999999999998.

If you want a detailed explanation, check out this article.

If you want the functionality, use Math.round():

>>> (Math.round(17.06 * 100) === 1706)
true
BenM
  • 52,573
  • 26
  • 113
  • 168