Click here to Skip to main content
14,664,385 members
Rate this:
Please Sign up or sign in to vote.
In angular 6 i am getting the invalid values when adding the large value numbers.

Is there any solution around this to handle large numbers for addition, comparison, etc?


What I have tried:

9007199254740992==9007199254740993 
o/p = true

9007199254740992+0.98 
o/p = 9007199254740992
Posted
Updated 20-May-19 22:50pm

Rate this:
Please Sign up or sign in to vote.

Solution 1

Numbers in JavaScript cannot be arbitrarily large or precise - numbers are 64-bit values (based on the IEEE 754 standard) and you've hit the limit with your number. You'll have to use an external library such as bignumber.js[^] for arbitrary precision.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Those are JavaScript 'features'. You may find many workarounds on the web. See, for instance Working with large integers in JavaScript[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100