format method

  1. @override
String? format(
  1. Decimal? decimal
)
override

Implementation

@override
String? format(final Decimal? decimal) {
  if (decimal == null) {
    return null;
  }

  List<String> parts = decimal.doubleValue
      .toStringAsFixed(precision)
      .replaceAll('.', '')
      .replaceAll('-', '')
      .split('')
      .reversed
      .toList();

  int start = precision + 4;
  if (precision > 0) {
    parts.insert(precision, decimalSeparator);
  } else {
    start = 3;
  }

  for (int pos = start; parts.length > pos; pos += 4) {
    parts.insert(pos, thousandSeparator);
  }

  if (decimal.doubleValue < 0) {
    parts.add('-');
  }

  return parts.reversed.join();
}