Dart数字转汉字

class ConvertNumberToChineseMoneyWords{
  // 大写数字
  static List NUMBERS = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十",""];

  static String toChinese(int index) {
    if(index > 100){
      return index.toString();
    }
    StringBuffer stringBuffer = StringBuffer();
    if(index / 10 < 1){
      return NUMBERS[index];
    }
    int tenUnit = (index / 10).toInt();
    int remainder = index % 10;
    if(remainder == 9){
      tenUnit++;
      remainder = 10;
    }
    if(tenUnit == 1){
      stringBuffer..write("十")..write(NUMBERS[remainder]);
      return stringBuffer.toString();
    }
    stringBuffer..write(NUMBERS[tenUnit - 1])..write("十")..write(NUMBERS[remainder]);
    return stringBuffer.toString();
  }
}

你可能感兴趣的:(Dart数字转汉字)