zoukankan      html  css  js  c++  java
  • Java实现将数字转为大写汉字

    public class Int2Big { 
        static String int2big(int src) { 
            final String num[] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; 
            final String unit[] = {"圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"}; 
            String dst = ""; 
            int count = 0; 
            while (src > 0) { 
                dst = (num[src % 10] + unit[count]) + dst; 
                src = src / 10; 
                count++; 
            } 
            return dst.replaceAll("零[仟佰拾]", "零").replaceAll("零+万", "万") 
                    .replaceAll("零+亿", "亿").replaceAll("亿万", "亿零") 
                    .replaceAll("零+", "零").replaceAll("零圆", "圆"); 
        } 
    
        public static void main(String[] args) { 
            System.out.println(int2big(123004506)); //-->壹亿贰仟叁佰万肆仟伍佰零陆圆 
            System.out.println(int2big(6523464)); //-->陆佰伍拾贰万叁仟肆佰陆拾肆圆 
            System.out.println(int2big(1001000100));//-->壹拾亿零壹佰万零壹佰圆 
            System.out.println(int2big(808)); //-->捌佰零捌圆 
        } 
    }

     转自:https://www.v2ex.com/t/388568#reply41

  • 相关阅读:
    05.九个内置对象
    04.线程面试题-01
    03.反射杂谈
    02.Java动态代理实现与原理分析之静态代理
    01.JDBC技术摘要
    异步请求二
    表单验证(添加数据)
    异步请求(删除json数据)
    异步请求(解析json数据)
    异步请求(获取json数据)
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/7485837.html
Copyright © 2011-2022 走看看