formatDecimal method

  1. @override
String formatDecimal (int number)
override

Formats number as a decimal, inserting locale-appropriate thousands separators as necessary.

Implementation

@override
String formatDecimal(int number) {
  if (number > -1000 && number < 1000)
    return number.toString();

  final String digits = number.abs().toString();
  final StringBuffer result = StringBuffer(number < 0 ? '-' : '');
  final int maxDigitIndex = digits.length - 1;
  for (int i = 0; i <= maxDigitIndex; i += 1) {
    result.write(digits[i]);
    if (i < maxDigitIndex && (maxDigitIndex - i) % 3 == 0)
      result.write(',');
  }
  return result.toString();
}