JavaScript parseInt is giving me wrong number, what I'm doing wrong?

前端 未结 1 802
难免孤独
难免孤独 2020-12-12 03:34

So, for parseInt(\'10152547376283911\', 10) I\'m expecting 10152547376283911, but I\'m getting 10152547376283912.

What I\'m doing wrong?

相关标签:
1条回答
  • 2020-12-12 03:56

    Javascript native numbers do not have enough precision (significant digits) to hold the number you are expecting. See the question What JavaScript library can I use to manipulate big integers? for suggestions on how to deal with this problem.

    Depending on your application, you may actually be able to use strings instead of numbers (for example, if your number represents something like a physical part number). You would only need a bigint library if you intend to do arithmetic on your numbers.

    0 讨论(0)
提交回复
热议问题