What is the standard solution in JavaScript for handling big numbers (BigNum)?

Update(2019-08-19): BigInt is now part of Firefox and Chrome; you no longer need a library: const bigInt1 = 1111111111111111111111111111111n; const bigInt2 = BigInt(“1111111111111111111111111111111″) console.log((bigInt1 + bigInt2)+””) Original answer: If you need arbitrary-precision decimal numbers, use Javascript-bignum, as it is correct and fast.

PHP – Floating Number Precision [duplicate]

Because floating point arithmetic != real number arithmetic. An illustration of the difference due to imprecision is, for some floats a and b, (a+b)-b != a. This applies to any language using floats. Since floating point are binary numbers with finite precision, there’s a finite amount of representable numbers, which leads accuracy problems and surprises … Read more

Large numbers erroneously rounded in JavaScript

You’re overflowing the capacity of JavaScript’s number type, see §8.5 of the spec for details. Those IDs will need to be strings. IEEE-754 double-precision floating point (the kind of number JavaScript uses) can’t precisely represent all numbers (of course). Famously, 0.1 + 0.2 == 0.3 is false. That can affect whole numbers just like it … Read more