Javascript中有限制大数字的小数位吗? [英] Is there a limit in Javascript to decimal places on big floats?

查看:115
本文介绍了Javascript中有限制大数字的小数位吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是什么原因造成的?是小数位限制为大数字/浮动?



是否与IEEE 754标准有关(如此处解释:浮点数学是否被打破?)?

最后 - 怎么样我来解决这个问题吗?是的,你看到了64位浮点固有的限制。如果你真的需要两个以上的小数位数,如123,456,789,201,234那么大,你需要某种扩展的算术库。 这个问题有一些建议和讨论。


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.

这篇关于Javascript中有限制大数字的小数位吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆