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.

2

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.