数字转换为壹仟贰佰叁拾肆的Java方法
网银转帐时, 填写金额后下方出现的汉字金额, 这是Java下的实现.
public static String toRMB(double money) { char[] s1 = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'}; char[] s4 = {'分', '角', '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万'}; String str = String.valueOf(Math.round(money * 100 + 0.00001)); String result = ""; boolean zeroFlag = false; for (int i = 0; i < str.length(); i++) { int n = str.charAt(i) - '0'; int level = str.length() - i - 1; if (n == 0) { zeroFlag = true; if (level % 4 == 2) result += "" + s4[level]; } else { if (zeroFlag) { result += "零"; zeroFlag = false; } result += "" + s1[n] + s4[level]; } } return result.replaceAll("亿万", "亿").replaceAll("元$", "元整"); }