Why is console.log (10150141932135203) printing 10150141932135204 in both Firefox and Chrome, and how can I handle such large integer values?

I tried to find out why one of our clients on Facebook was having problems, and I traced it to 10150141932135203, turning into 10150141932135204, giving us pretty unexpected results.

$ node
> 10150141932135203
10150141932135204
> 10150141932135204
10150141932135204
> 10150141932135205
10150141932135204
> 10150141932135206
10150141932135206
> 10150141932135207
10150141932135208
> 10150141932135208
10150141932135208
> 10150141932135209
10150141932135208
> 10150141932135210
10150141932135210

How can I deal with integers of this size?

+5
source share
1 answer

If numbers are larger than the IEEE 754 specification allows (2 53 ), they will lose accuracy as your examples demonstrate.

Binary Coded Decimal JavaScript, . BCMathJs.

, , , . , .

+4

All Articles