Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1.06 KB

File metadata and controls

28 lines (20 loc) · 1.06 KB

JavaScript handles numbers using the 64-bit binary format, known as double-precision floating point format.

This means that only numbers between - (2^53 - 1) and + (2^53 - 1) can be stored and manipulated without loss of accuracy. The upper limit is stored as a constant in JS under Number.MAX_SAFE_INTEGER:

console.log (Number.MAX_SAFE_INTEGER)
// 9007199254740991

console.log (9007199254740991 - 1 === 9007199254740991 - 2)
// false

console.log (9007199254740991 + 1 === 9007199254740991 + 2)
// true

You can check whether a number can be stored accurately by using the method Number.isSafeInteger():

console.log (Number.isSafeInteger (9007199254740990))
// true

console.log (Number.isSafeInteger (9007199254740992))
// false

Further reference: