How can I handle numbers bigger than 17-digits in Firefox/IE7?

后端 未结 4 1325
遇见更好的自我
遇见更好的自我 2020-12-06 12:06

For a web application I want to be able to handle numbers up to 64 bits in size. During testing, I found that javascript (or the browser as a whole) seems to handle as much

相关标签:
4条回答
  • 2020-12-06 12:24

    In Javascript, all numbers are IEEE double precision floating point numbers, which means that you only have about 16 digits of precision; the remainder of the 64 bits are reserved for the exponent. As Fabien notes, you will need to work some tricks to get more precision if you need all 64 bits.

    0 讨论(0)
  • 2020-12-06 12:35

    I think you need to treat them as strings if you have reached Javascript limit (see here)

    0 讨论(0)
  • 2020-12-06 12:35

    You could try to split them into two or more numbers (in a class maybe), but you'll might need some arithmetic helper functions to work with them.

    Cheers

    0 讨论(0)
  • 2020-12-06 12:46

    As others note, JS implements doubles, so you'll have to look elsewhere to handle bigger numbers. BigInt is a library for arbitary precision math for integers.

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