MDN状态:
Numbers in JavaScript are "double-precision 64-bit format IEEE 754 values", according to the spec. This has some interesting consequences. There's no such thing as an integer in JavaScript, so you have to be a little careful with your arithmetic if you're used to math in C or Java.
这表明所有数字都是float
。有什么方法可以使用 int
egers,而不是 float
?
最佳答案
Javascript 中实际上只有几种数据类型:对象、数字和字符串。如你所见,JS 数字都是 64 位 float 。没有整数。
Firefox 4 将支持类型化数组,您可以在其中拥有真实 整数数组,例如:https://developer.mozilla.org/en/JavaScript_typed_arrays
在那之前,有一些骇人听闻的方法可以将整数数组存储为字符串,并使用 charCodeAt()
提取每个整数。
关于javascript - JavaScript 中的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4703725/