[英]How can I store an integer number that's greater than 2147483647 in Javascript?
From what I understand integers range from据我所知,整数范围从
-2147483648 through 2147483647
I am confused because I noticed some references to big int in javascript.我很困惑,因为我注意到 javascript 中一些对 big int 的引用。 Can someone explain how I can store an integer number larger than 2147483647?
有人可以解释我如何存储大于 2147483647 的整数吗?
BigInteger.js是一个用于 Javascript 的任意长度整数库,允许对无限大小的整数进行算术运算,尽管有内存和时间限制。
Depending on what you are doing the number, you can handle integers up to +/- (2^53)-1 or 9007199254740991
.根据您所做的数字,您可以处理高达 +/- (2^53)-1 或
9007199254740991
。
While not all browsers support Number.MAX_SAFE_INTEGER
yet, you can calculate it with:虽然并非所有浏览器都支持
Number.MAX_SAFE_INTEGER
但您可以使用以下方法计算它:
Math.pow(2, 53) - 1
Note: This works when in pure math functions, but many bitwise operations are limited to 16 bit integers, as well as the index in arrays.注意:这在纯数学函数中有效,但许多按位运算仅限于 16 位整数,以及数组中的索引。
More details can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER更多细节可以在这里找到: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
two ways we can store big int我们可以通过两种方式存储 big int
const bigIntVal=123243435454656565657575n;
or或
const bigIntVal=BigInt("123243435454656565657575");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.