美文网首页
Dart数字转汉字

Dart数字转汉字

作者: 吃饱了就送 | 来源:发表于2022-06-17 15:07 被阅读0次
    class ConvertNumberToChineseMoneyWords{
      // 大写数字
      static List<String> 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数字转汉字

          本文链接:https://www.haomeiwen.com/subject/ikchvrtx.html