toWord static method

String toWord(
  1. String? number,
  2. StrType type, {
  3. String separator = ',',
  4. bool isMoney = false,
  5. String biggerThanCapacity = "طول عدد باید کمتر از 16 رقم باشد.",
})

Implementation

static String toWord(String? number, StrType type,
    {String separator: ',',
      bool isMoney: false,
      String biggerThanCapacity: "طول عدد باید کمتر از 16 رقم باشد."}) {

  String _words = "";
  String _result = "";


  if (number == null || number == "") {
    return '';
  }
  if (number.length >= 15) {
    return biggerThanCapacity;
  }

  ///remove separator ','  symbol of text
  String numInt = number.replaceAll(separator, '');

  switch (type) {
    case StrType.NumWord:
      _words = _NumWord.toWord(numInt, isMoney);
      break;
    case StrType.StrWord:
      _words = _StrWord.toWord(numInt, isMoney);
      break;
  }

  _result = _words.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");

  return _result.trim();
}