工具類之阿拉伯數字轉中文

    /**
	 * 阿拉伯數字轉中文數字(簡體)
	 * 
	 * @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("零$", "");
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章