Reputation: 14835
I'm trying to convert a big/very long numeric string into a number:
+'-000000098765432112345.67898765432100000';
'-000000098765432112345.67898765432100000'*1;
parseFloat('-000000098765432112345.67898765432100000', 10);
All these tests will output -98765432112345.67
instead of the expected -98765432112345.678987654321
.
Why does it happens?
NB: The proposed duplicated solution doesn't answer my question, it just gives a solution to the problem.
Upvotes: 1
Views: 99
Reputation: 5536
The usual cause with big numbers is because of overflow: https://en.wikipedia.org/wiki/Arithmetic_overflow.
This answers the similar question 'at what point will overflow occur in Javascript': What is JavaScript's highest integer value that a Number can go to without losing precision?
Upvotes: 2