0

I'm new in developing javascript apps, i have a doubt about a behaviour that i'm going to try to explain.

If i execute:

Number(5555555555555555);

Result: 5555555555555555

But if i execute:

Number(55555555555555555);

Result: 55555555555555550

Anybody can explain to me what is the reason of this? Thanks!!

yuriy636
  • 11,171
  • 5
  • 37
  • 42

2 Answers2

1

If you need to work with such big numbers I would suggest you use some of the big integer libraries such as this. The reason this happens as far as I know is the way processors and memory work. It's no related to some "bug" in JS.

Biser A.
  • 154
  • 1
  • 13
1

Integers (numbers without a period or exponent notation) are accurate up to 15 digits. Javacript simply adds zeros to keep the number accurate in terms of its digit length.

Documentation

Eternal
  • 303
  • 1
  • 2
  • 16