Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
The problem it's not javascript itself, but it's the limitation of floating point variable with representation error in decimal base.
So 0.99999999999999999 is rounded to 1 -
As far as I know that is a problem with Math itself: http://relativelyinteresting.com/do...
-
crisz82368yvar a = 1;
a=a/3; //a: 0.3333333...
a=a*3; //a: 0.9999999...
Now tell me, is "a" an integer or a decimal? -
Math tells us that 0.(9) = 1, check on your calculator.
Do you know why?
1/9 = 0.(1)
2/9 = 0.(2)
3/9 = 0.(3)
...
9/9 = 1 = 0.(9)
Isn't that interesting? -
-
kdev658yI think it has something to do with our base10 decimal system vs calculator/machine base2 (binary) repesentation of base10 number. So "close enough" is as acurate as is possible. But javascript does have some odd quirks lol.
Related Rants
Welcome to JavaScript where
Number.isInteger(0.9999999999999999) is false and
Number.isInteger(0.99999999999999999) is true
undefined
javascript
int
quirk
wtf