Prevent JavaScript Number function from rounding big numbers

后端 未结 4 1953
自闭症患者
自闭症患者 2020-11-28 16:17

I have a string value \' 9223372036854775807 \'. I use Number() function in JavaScript to convert it to a number value using the following Code

var numericVa         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 16:26

    It's seems that your number is greater than 2^53, biggest integer number in javascript which can be represented without loosing precision (see this question).

    If you really need to operate big numbers, you could use special libraries like this one: https://github.com/peterolson/BigInteger.js

提交回复
热议问题