数字金额转化为中文金额样式
public static void parse(float number){ BigDecimal big = new BigDecimal(number); big = big.setScale(2, 4); String money = String.valueOf(big); //整数部分 String firstMoney = money.substring(0, money.indexOf(".")).trim(); //小数部分 String nextMoney = money.substring(money.indexOf(".") + 1).trim(); //整数金额 char firstNameChar[] = firstMoney.toCharArray(); String firstName[] = new String[firstNameChar.length]; for(int i = 0; i < firstNameChar.length; i ++){ firstName[i] = String.valueOf(firstNameChar[i]); } //壹 贰 叁 肆 伍 陆 柒 捌 String RNBName[] = new String[]{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; //拾 佰 仟 万 亿 圆 String RNB[] = new String[]{"圆","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万"}; //记录上一个数位0 boolean flagZero = false; //记录当前位置单位级数 int pos = firstName.length - 1; for(int i = 0; i < firstName.length; i ++,pos --){ //当前数值 int num = Integer.parseInt(firstName[i]); //当前数位0 if(num == 0){ //添加圆、万、亿 if(pos == 0 || pos == 4 || pos == 8){ firstName[i] = RNB[pos]; flagZero = false; } else{ //这里0不用读出来,清除 firstName[i] = ""; //记住这里有零, flagZero = true; } } else{ if(flagZero == true){ //有零时加上“零” firstName[i] = "零" + RNBName[num] + RNB[pos]; }else{ firstName[i] = RNBName[num] + RNB[pos]; } } } //小数部分金额进行四舍五入,只有4种情况(00,01,10,11) String nextName[] = new String[2]; nextName[0] = nextMoney.substring(0, 1); nextName[1] = nextMoney.substring(1, 2); //小数金额 String floatName = ""; if(nextName[0].equals("0")){ if(nextName[1].equals("0")){ floatName = "整"; } else{ floatName = RNBName[Integer.parseInt(nextName[1])] + "分"; } } else{ if(nextName[1].equals("0")){ floatName = RNBName[Integer.parseInt(nextName[0])] + "角"; } else{ floatName = RNBName[Integer.parseInt(nextName[0])] + "角" + RNBName[Integer.parseInt(nextName[1])] + "分"; } } StringBuffer CHMoney = new StringBuffer(); for(String str:firstName){ CHMoney.append(str); } CHMoney.append(floatName); System.out.println(CHMoney); }