toFixed method

String toFixed(
  1. BigInt x
)

Implementation

String toFixed(BigInt x) {
  bool isNegative = x < BigInt.zero;
  x = x.abs();
  BigInt base = BigInt.from(10).pow(4);
  String mod = (x % base).toString();
  String m = (x ~/ base).toString();

  // 0-pad
  while (mod.length % 4 != 0) {
    mod = '0' + mod;
  }

  return '${isNegative ? '-' : ''}$m.$mod';
}