0

If I do assign variable x = "189371971441827056" and then I do,

parseInt(x) 189371971441827070

The value of parseInt(x) changes. I don't understand why?

Thanks in advance...!!

Nimesh jani
  • 23
  • 2
  • 7
  • 5
    That number is probably larger than the largest int javascript can keep track of. – takendarkk Mar 13 '20 at 15:58
  • big int numbers are actually store like floating points number in javascript , so you have a rounding error inherent to the IEEE standard – Pac0 Mar 13 '20 at 15:58
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – evolutionxbox Mar 13 '20 at 15:59
  • Number.MAX_SAFE_INTEGER = 9007199254740991 – j08691 Mar 13 '20 at 15:59
  • Try using BigNumber variable precision math. https://mathjs.org/docs/datatypes/bignumbers.html There are several big number libraries out there, this one is just the first one I found. – UncaAlby Mar 13 '20 at 16:03
  • None of them helped. How do I get an int from above value? – Nimesh jani Mar 13 '20 at 16:13
  • 1
    `BigInt(x)`, You can't use `parseInt` because it's too big for Javascript number type. – Keith Mar 13 '20 at 16:15

0 Answers0