首页 > 代码库 > 人民币数字金额转大写金额

人民币数字金额转大写金额

public class t {	public static String Trans2RMB(String money) {		int index = money.indexOf(".");		if (index < 0) {// 没有角分			money = money + ".00";			index = money.indexOf(".");		}		if (money.substring(index, money.length()).length() < 3) {// 没有分			money = money + "0";			index = money.indexOf(".");		}		money = money.replaceAll("\\D", "");// 去除"."		int length = money.length();		// 货币大写形式		String bigLetter[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };		// 货币单位		String unit[] = { "仟", "佰", "拾", "万", "仟", "佰", "拾", "亿", "仟", "佰",				"拾", "万", "仟", "佰", "拾", "元", "角", "分" };		StringBuffer buf = new StringBuffer("");		for (int i = 0; i < length; i++) {			int num = Integer.parseInt(String.valueOf(money.charAt(i)));			buf.append(bigLetter[num]);			buf.append(unit[unit.length - money.length() + i]);		}		String moneyTmp = buf.toString();		buf = null;		for (int i = 0; i < 4; i++) {			// 亿 万 元是四个为单元的最后一位例如1234(亿)4567(万)7891(元)			moneyTmp = moneyTmp.replaceAll("零亿", "亿");			moneyTmp = moneyTmp.replaceAll("零万", "万");			moneyTmp = moneyTmp.replaceAll("零仟", "零");			moneyTmp = moneyTmp.replaceAll("零佰", "零");			moneyTmp = moneyTmp.replaceAll("零拾", "零");			moneyTmp = moneyTmp.replaceAll("零元", "元");			moneyTmp = moneyTmp.replaceAll("零角", "零");			moneyTmp = moneyTmp.replaceAll("零分", "整");		}		moneyTmp = moneyTmp.replaceAll("亿万", "亿");		moneyTmp = moneyTmp.replaceAll("拾元", "拾元零");		moneyTmp = moneyTmp.replaceAll("[零]{1,}", "零");// 多个连续的零替换为一个零		moneyTmp = moneyTmp.replaceAll("零整", "整");		return moneyTmp;	}	public static void main(String[] args) {		String money;		money = "230067890080.01";		System.out.println(Trans2RMB(money));		money = "230067890080.11";		System.out.println(Trans2RMB(money));		money = "230067890080.10";		System.out.println(Trans2RMB(money));		money = "230067890081.01";		System.out.println(Trans2RMB(money));		money = "230067890081.11";		System.out.println(Trans2RMB(money));		money = "230067890081.10";		System.out.println(Trans2RMB(money));		money = "230067890080.01";		System.out.println(Trans2RMB(money));		money = "230667890080.01";		System.out.println(Trans2RMB(money));		money = "230007890080.01";		System.out.println(Trans2RMB(money));		money = "230607890080.01";		System.out.println(Trans2RMB(money));		money = "200067890080.01";		System.out.println(Trans2RMB(money));		money = "200067890080.11";		System.out.println(Trans2RMB(money));		money = "200067890080.10";		System.out.println(Trans2RMB(money));		money = "200007890080.01";		System.out.println(Trans2RMB(money));		money = "200000890080.11";		System.out.println(Trans2RMB(money));		money = "200000090080.10";		System.out.println(Trans2RMB(money));		money = "200000000080.10";		System.out.println(Trans2RMB(money));		money = "200007890080";		System.out.println(Trans2RMB(money));		money = "200000890080.1";		System.out.println(Trans2RMB(money));		money = "200607890080.01";		System.out.println(Trans2RMB(money));		money = "200600890080.11";		System.out.println(Trans2RMB(money));		money = "200600090080.10";		System.out.println(Trans2RMB(money));		money = "200600000080.10";		System.out.println(Trans2RMB(money));		money = "20007800080.01";		System.out.println(Trans2RMB(money));		money = "10001.01";		System.out.println(Trans2RMB(money));		// System.out.println(new		// StringBuffer(Arrays.toString(unit)).reverse());		// String small[] = { "分", "角" };		// String[] ss = new String[] { "", "元" };		// System.out.println(MoneyUtil.Trans2RMB("."));		// System.out.println(MoneyUtil.Trans2RMB(".0"));		// System.out.println(MoneyUtil.Trans2RMB("0.0"));		// System.out.println(MoneyUtil.Trans2RMB("0.00"));		// System.out.println(MoneyUtil.Trans2RMB("0.000"));		// System.out.println(MoneyUtil.Trans2RMB("123456789.0"));		// System.out.println(MoneyUtil.Trans2RMB("1234"));		// System.out.println(MoneyUtil.Trans2RMB("1111."));		// System.out.println(MoneyUtil.Trans2RMB("1011.011"));		// System.out.println(MoneyUtil.Trans2RMB("00012340000000000.011"));		//		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾元零壹分		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾元零壹角壹分		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾元零壹角整		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾壹元零壹分		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾壹元壹角壹分		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾壹元壹角整		// 贰仟叁佰亿陆仟柒佰捌拾玖万零捌拾元零壹分		// 贰仟叁佰零陆亿陆仟柒佰捌拾玖万零捌拾元零壹分		// 贰仟叁佰亿零柒佰捌拾玖万零捌拾元零壹分		// 贰仟叁佰零陆亿零柒佰捌拾玖万零捌拾元零壹分		// 贰仟亿陆仟柒佰捌拾玖万零捌拾元零壹分		// 贰仟亿陆仟柒佰捌拾玖万零捌拾元零壹角壹分		// 贰仟亿陆仟柒佰捌拾玖万零捌拾元零壹角整		// 贰仟亿零柒佰捌拾玖万零捌拾元零壹分		// 贰仟亿零捌拾玖万零捌拾元零壹角壹分		// 贰仟亿零玖万零捌拾元零壹角整		// 贰仟亿零捌拾元零壹角整		// 贰仟亿零柒佰捌拾玖万零捌拾元整		// 贰仟亿零捌拾玖万零捌拾元零壹角整		// 贰仟零陆亿零柒佰捌拾玖万零捌拾元零壹分		// 贰仟零陆亿零捌拾玖万零捌拾元零壹角壹分		// 贰仟零陆亿零玖万零捌拾元零壹角整		// 贰仟零陆亿零捌拾元零壹角整		// 贰佰亿零柒佰捌拾万零捌拾元零壹分	}}