美文网首页
【Dart/Flutter】中对于BigInt的一些操作

【Dart/Flutter】中对于BigInt的一些操作

作者: 坐了整个春夏秋冬 | 来源:发表于2022-01-07 10:52 被阅读0次

Dart中BigInt的基本计算函数

  /// Addition operator.
  BigInt operator +(BigInt other);

  /// Subtraction operator.
  BigInt operator -(BigInt other);

  /// Multiplication operator.
  BigInt operator *(BigInt other);

  /// Division operator.
  double operator /(BigInt other);
  • Dart中对于大数字只有一个BigInt,没有像Java中的BigDecimal,要实现小数计算需要一点小技巧。
    例如,我们想要将大数字99(假设他是99999...超大的数),乘以一个浮点数1.5,可以通过如下方式:
  double d = 1.5;
  BigInt bigNum = BigInt.from(99);
  bigNum = bigNum * BigInt.from(d * 10);
  bigNum = bigNum ~/ BigInt.from(10);

相关文章

网友评论

      本文标题:【Dart/Flutter】中对于BigInt的一些操作

      本文链接:https://www.haomeiwen.com/subject/dhkjcrtx.html