简体   繁体   中英

Is there a limit in Javascript to decimal places on big floats?

I'm facing the following issue/behavior:

console.log(1234567892012.123456);   // 1234567892012.1234
console.log(12345678920123.123456);  // 12345678920123.123
console.log(123456789201234.123456); // 123456789201234.12

What is causing this? Are decimal places limited for big numbers/floats?

Is it related to the IEEE 754 standard (as explained here: Is floating point math broken? )?

And finally - how can I come around this issue?

Yes, you are seeing the inherent limitations of 64-bit floating point. If you really need more than two decimal places on a number as big as 123,456,789,201,234, you need some sort of extended arithmetic library. This question has some suggestions and discussion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM