1

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.

Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
  • Possible duplicate of [What is the standard solution in Javascript for handling big numbers (BigNum)?](http://stackoverflow.com/questions/3072307/what-is-the-standard-solution-in-javascript-for-handling-big-numbers-bignum) – Ian Grainger Jan 18 '16 at 11:21
  • It doesn't answer my question, I want to know why it happens. – Fez Vrasta Jan 18 '16 at 11:23

1 Answers1

2

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?

Community
  • 1
  • 1
Ian Grainger
  • 5,148
  • 3
  • 46
  • 72