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 ?
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 ?
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