toStringAsFixed method

String toStringAsFixed(
  1. int fractionDigits
)

A decimal-point string-representation of this number with fractionDigits digits after the decimal point.

Implementation

String toStringAsFixed(int fractionDigits) {
  assert(fractionDigits >= 0);
  if (fractionDigits == 0) return round().toBigInt().toString();
  final value = round(scale: fractionDigits);
  final intPart = value.toBigInt().abs();
  final decimalPart =
      (one + value.abs() - intPart.toDecimal()).shift(fractionDigits);
  return '${value < zero ? '-' : ''}$intPart.${decimalPart.toString().substring(1)}';
}