What is JavaScript's highest integer value that a Number can go to without losing precision?

Is this defined by the language? Is there a defined maximum? Is it different in different browsers?

Answers


+/- 9007199254740991

ECMA Section 8.5 - Numbers

Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number type (indeed, the integer 0 has two representations, +0 and −0).

They are 64-bit floating point values, the largest exact integral value is 253-1, or 9007199254740991. In ES6, this is defined as Number.MAX_SAFE_INTEGER.

Note that the bitwise operators and shift operators operate on 32-bit ints, so in that case, the max safe integer is 231-1, or 2147483647.


Test it out!

var x = 9007199254740992;
var y = -x;
x == x + 1; // true !
y == y - 1; // also true !
// Arithmetic operators work, but bitwise/shifts only operate on int32:
x / 2;      // 4503599627370496
x >> 1;     // 0
x | 1;      // 1

Need Your Help

Playing BG Music Across Activities in Android

java android media music background-music

Hello! First time to ask a question here at stackoverflow. Exciting! Haha.

Is needed to release jboolean using JNI?

c++ jni cocos2d-x

I 'm trying to call a Static method from C++ to Java. But I get the following error:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.