Does JavaScript support 64-bit integers?

I was wondering if JavaScript is wrong in 64-bit integers, or am I doing something wrong?

I have the following code:

var str = "0x4000000000000000"; //4611686018427387904 decimal var val = parseInt(str); alert(val); 

I get this value: "4611686018427388000", which is 0x4000000000000060

+62
javascript integer 64bit
Mar 10 '12 at 3:13
source share
2 answers

JavaScript presents numbers using the IEEE-754 double-precision format (64 bits). As far as I understand, this gives you an accuracy of 53 bits or from fifteen to sixteen decimal digits. Your number has more digits than JavaScript can handle, so you get an approximation.

This is actually not a β€œmistreatment,” but obviously it is not very useful if you need full precision for large numbers. There are several JS libraries that can handle large numbers, such as BigNumber and Int64 .

+67
Mar 10 '12 at 3:18
source share

Chrome version 57 and later supports arbitrary precision integers. This is called BigInt, and it also works for other browsers. This is significantly faster than the JavaScript implementation.

+1
Jun 06 '18 at 16:38
source share



All Articles