English 中文(简体)
js 缺少整数
原标题:js missing integer

Javascript 无法在窗口中使用 1010040182222940525 这样的像 Conn 文件夹。 为什么 js 会以这个数字失败?

您可以查看示例,

http://jsfiddle.net/ymutlu/yCpWh/1/

最佳回答

在 IEEE 浮动点类型数字中,数字越多,数字之间的差就越大。当您查看 < a href=" http://en.wikipedia.org/wiki/Double-precision_floating-point_format" rel=“nofollow” > 编号如何存储 时,它就很有意义。

认为可能值的数量与非负表示值的负表示值相同。 这意味着在0和1之间, 可能数字的数量与在1和无穷之间的数字相同。 显然, 1和无穷之间的数字间隔最大。 这个间距实际上分布得越远, 可能存储的数字之间距离越远, 可能存储的数字之间的差越大( 没有实际的最大数字, 最终会到达无法区分数字与无穷的点 ) 。

这实际上非常有效, 因为在大多数情况下, 在处理较大数字时您需要的精确度要小一些。 10100401822940524 10100401822940526 之间的差别远小于 1 3 与数字大小的差别。 能够代表数字 2 比数字 10100401822940525 还要重要得多, 您只能代表64位数。

问题回答

I found this: http://gskinner.com/blog/archives/2011/03/the-case-of-the-disappearing-number.html

不知道他是否正确,但听起来合理。 ))

这是浮动点四舍五入的例子。 Javascript 中的数字作为双精度浮点数存储( AFAIK ) 。 浮点数的精确度有限, 所以当数字太大时, 它们就不能再作为精确的整数存储, 需要四舍五入 。

下面是另一个错误较大的例子。 http://jsfiddle.net/NhZ75/

如果您想知道数学为何起作用, 这是因为大多数计算机使用的浮点数比存储的精确度高, 所以圆差通常只有在将数字存储在变量中时才发生。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签