如何在 Dart 中创建一个 BigInt

How to create a BigInt in Dart

我正在尝试在 Dart 中创建一个 BigInt 以了解 BigInt。

我试过了

var x = 237462836487263478235472364782364827648632784628364;

但这会出错,因为编译器认为它是一个 int 但大于 64 位。

然后我看到,所以我试了一下:

var x = BigInt.from(237462836487263478235472364782364827648632784628364);

仍然给出同样的错误:

The integer literal 237462836487263478235472364782364827648632784628364 can't be represented in 64 bits.

Try using the BigInt class if you need an integer larger than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808.

我以为我在使用 BigInt class。

查看源代码,原来从数字文字创建BigInt的方法是从字符串解析它:

final x = BigInt.parse('237462836487263478235472364782364827648632784628364');
final y = BigInt.from(1);
final z = x + y;
// 237462836487263478235472364782364827648632784628365