displayValue property

String get displayValue

Implementation

String get displayValue {
  final firstBI = value ~/ BigInt.from(10).pow(decimals);

  final secondBI = value % BigInt.from(10).pow(decimals);

  final string = '$firstBI.${secondBI.toString().padLeft(decimals, '0')}';

  final lastNonZeroIndex = string.lastIndexOf(RegExp(r'[^0]'));

  if (lastNonZeroIndex == -1) return string;

  final formatted =
      string.substring(0, lastNonZeroIndex < 3 ? 3 : lastNonZeroIndex + 1);

  if (formatted.endsWith('.')) {
    return formatted.substring(0, formatted.length - 1);
  }

  return formatted;
}