convert static method

String convert(
  1. int number
)

handle converter

Implementation

static String convert(int number) {
  // 0 to 999 999 999 999
  if (number == 0) {
    return _zero;
  }
  final String strNumber = number.toString().padLeft(12, '0');
  // XXXnnnnnnnnn
  final int billions = int.parse(strNumber.substring(0, 3));
  // nnnXXXnnnnnn
  final int millions = int.parse(strNumber.substring(3, 6));
  // nnnnnnXXXnnn
  final int hundredThousands = int.parse(strNumber.substring(6, 9));
  // nnnnnnnnnXXX
  final int thousands = int.parse(strNumber.substring(9, 12));

  final String tradBillions = _getBillions(billions);
  String result = tradBillions;

  final String tradMillions = _getMillions(millions);
  result = result + tradMillions;

  final String tradHundredThousands = _getThousands(hundredThousands);
  result = result + tradHundredThousands;

  String tradThousand;
  tradThousand = _convertLessThanOneThousand(thousands, true);
  result = result + tradThousand;

  // remove extra spaces!
  result =
      result.replaceAll(RegExp('\\s+'), ' ').replaceAll('\\b\\s{2,}\\b', ' ');
  return result.trim();
}