且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript 长整数

更新时间:2023-09-29 08:44:34

在 Java 中,您有 64 位整数,而这正是您正在使用的.

In Java, you have 64 bits integers, and that's what you're using.

在 JavaScript 中,所有数字都是 64 位浮点数.这意味着您不能在 JavaScript 中表示所有的 Java 长.尾数的大小约为 53 位,这意味着您的数字 793548328091516928 无法准确表示为 JavaScript 数字.

In JavaScript, all numbers are 64 bits floating point numbers. This means you can't represent in JavaScript all the Java longs. The size of the mantissa is about 53 bits, which means that your number, 793548328091516928, can't be exactly represented as a JavaScript number.

如果你真的需要处理这样的数字,你必须用另一种方式来表示它们.这可以是字符串,也可以是数字数组等特定表示.JavaScript 中提供了一些大数字"库.

If you really need to deal with such numbers, you have to represent them in another way. This could be a string, or a specific representation like a digit array. Some "big numbers" libraries are available in JavaScript.