Parse Float has a rounding limit? How can I fix this?

前端 未结 3 1101
小鲜肉
小鲜肉 2021-01-18 00:08

I set up a system that parses a compact data string into JSON. I\'m using a 19 digit number to store ids. Unfortunately any number greater than 17 digits, parseFloat()

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 00:20

    JavaScript has only one numeric type, which is an IEEE 754 double precision floating-point. That means, you have a maximum of 52 bits of precision, which is a bit more than 15 decimal places.

    If you need more precision than that, you have to use a bignum library or work with strings.

提交回复
热议问题