如何在 Firefox/IE7 中处理大于 17 位的数字? [英] How can I handle numbers bigger than 17-digits in Firefox/IE7?

查看:12
本文介绍了如何在 Firefox/IE7 中处理大于 17 位的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个 Web 应用程序,我希望能够处理最大为 64 位的数字.在测试过程中,我发现 javascript(或整个浏览器)似乎可以处理多达 17 位数字.一个 64 位的数字最多有 20 位数字,但是在 javascript 处理完数字后,将最低有效 3 位四舍五入并设置为 0....任何想法这是从哪里来的?更重要的是,知道如何解决它吗?

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 as 17 digits. A 64-bit number has a maximum of 20 digits, but after the javascript has handled the number, the least significant 3 digits are rounded and set to 0.... Any ideas where this comes from? More importantly, any idea how to work around it?

推荐答案

在 Javascript 中,所有数字都是 IEEE double精度 浮点数,这意味着您只有大约 16 位的精度;剩余的 64 位为指数保留.正如 Fabien 所说,如果您需要全部 64 位,则需要使用一些技巧来获得更高的精度.

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.

这篇关于如何在 Firefox/IE7 中处理大于 17 位的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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