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

折月煮酒 提交于 2019-12-29 01:51:05

问题


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

What I'm doing wrong?


回答1:


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.



来源:https://stackoverflow.com/questions/25233969/javascript-parseint-is-giving-me-wrong-number-what-im-doing-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!