dart中整数的最大值是多少?
What is the max value of integer in dart?
我找遍了所有地方,但找不到与此主题相关的任何信息。
另外,dart 中是否有 java - like Long / BigDecimal 数据类型?
这取决于您是 运行 在 Dart VM 中还是编译为 JavaScript。
在 Dart VM 上,int
是任意精度,没有限制。
当编译为 JavaScript 时,您实际上使用的是浮点数,因为这是 JavaScript 支持的全部内容。这意味着您只能表示 -253 到 253
范围内的整数
飞镖 2
对于 dart2js 生成的 JavaScript Pixel Elephants 答案仍然正确。
within the range -253 to 253
其他执行平台有固定大小的 64 位整数。
类型 BigInt
已添加到 typed_data
Since Dart 2.0 will switch to fixed-size integers, we also added a BigInt
class to the typed_data
library. Developers targeting dart2js can use this class as well. The BigInt
class is not implementing num, and is completely independent of the num hierarchy.
飞镖 1
还有包
- https://pub.dartlang.org/packages/bignum
- https://pub.dartlang.org/packages/decimal
我比较喜欢这个:
int hugeInteger = double.maxFinite.toInt()
我找遍了所有地方,但找不到与此主题相关的任何信息。 另外,dart 中是否有 java - like Long / BigDecimal 数据类型?
这取决于您是 运行 在 Dart VM 中还是编译为 JavaScript。
在 Dart VM 上,int
是任意精度,没有限制。
当编译为 JavaScript 时,您实际上使用的是浮点数,因为这是 JavaScript 支持的全部内容。这意味着您只能表示 -253 到 253
范围内的整数飞镖 2
对于 dart2js 生成的 JavaScript Pixel Elephants 答案仍然正确。
within the range -253 to 253
其他执行平台有固定大小的 64 位整数。
类型 BigInt
已添加到 typed_data
Since Dart 2.0 will switch to fixed-size integers, we also added a
BigInt
class to thetyped_data
library. Developers targeting dart2js can use this class as well. TheBigInt
class is not implementing num, and is completely independent of the num hierarchy.
飞镖 1
还有包
- https://pub.dartlang.org/packages/bignum
- https://pub.dartlang.org/packages/decimal
我比较喜欢这个:
int hugeInteger = double.maxFinite.toInt()