JavaScript’s Defects on Numbers

Number larger than 0×20000000000000 (54bit) will not be reliable.

Here is the test script:

javascript:alert (0x1ffffffffffffe);
javascript:alert (0x1fffffffffffff);
javascript:alert (0x20000000000000);
javascript:alert (0x20000000000001);

You can see that the latter two numbers are same number in JavaScript!

Conclusion

The safe number range for integer is “-0×1fffffffffffff - 0×1fffffffffffff” (53bit). Therefore, in Java to JavaScript world, conversion of Java’s long number to JavaScript’s Number may result in incorrect calculations.

Leave a Reply