4

Can someone please explain why all these parseInt operations evaluate to the same number 10153593963283296?

parseInt('10153593963283294') 10153593963283294

parseInt('10153593963283295') 10153593963283296

parseInt('10153593963283296') 10153593963283296

parseInt('10153593963283297') 10153593963283296

parseInt('10153593963283298') 10153593963283298

Tested in browsers and node command line.

Thanks!

2 Answers 2

4

Your number is larger than Number.MAX_SAFE_INTEGER. JavaScript stores even Integers as floating-point numbers and therefore you lose precision once your number becomes too large.

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

Comments

1

I assume it's because you've reached the MAX_SAFE_INTEGER.

Please, read this article:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

There's a note:

"The reasoning behind that number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1.

Safe in this context refers to the ability to represent integers exactly and to correctly compare them."

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.