工具类之阿拉伯数字转中文

2020-09-30 16:25发布

    /**
	 * 阿拉伯数字转中文数字(简体)
	 * 
	 * @param intNum
	 * @return 
	 */
	public static String int2chineseNum(int intNum) {
		String[] cnNum = 
            { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
		String[] cnUnit = 
            { "", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };
		String cnNegative = "负";
		StringBuffer sb = new StringBuffer();
		boolean isNegative = false;
		if (intNum < 0) {
			isNegative = true;
			intNum *= -1;
		}
 
		int count = 0;
		while (intNum > 0) {
			sb.insert(0, cnNum[intNum % 10] + cnUnit[count]);
			intNum = intNum / 10;
			count++;
		}
 
		if (isNegative) {
			sb.insert(0, cnNegative);
		}
 
		return sb.toString()
                    .replaceAll("零[千百十]", "零")
                    .replaceAll("零+万", "万")
                    .replaceAll("零+亿", "亿")			
                    .replaceAll("亿万", "亿零").replaceAll("零+", "零")
                    .replaceAll("零$", "");
	}

 

作者:咔啦永远OK

链接:https://blog.csdn.net/weixin_45764765/article/details/107174493

来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。