package com.luang.util.common; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * MoneyUtil.java * * @desc Money改换东西 * @author Guoxp * @datatime Apr 7, 2013 3:47:5 http://www.star1234.info 1 PM * */ public class MoneyUtil { private static final Pattern AMOUNT_PATTERN = Pattern.compile("^(0|[1-9]\\d{0,11})\\.(\\d\\d)$"); // 不考虑分隔符的正确性 private static final char[] RMB_NUMS = "零壹贰叁肆伍陆柒捌玖".toCharArray(); private static final String[] UNITS = {"元", "角", "分", "整"}; private static final String[] U1 = {"", "拾", "佰", "仟"}; private static final String[] U2 = {"", "万", "亿"}; /** * 将金额(整数有些等于或少于12位,小数有些2位)改换为中文大写方法. * @param amount 金额数字 * @return 中文大写 * @throws IllegalArgumentException */ public static String convert(String amount) throws IllegalArgumentException { // 去掉分隔符 amount = amount.replace(",", ""); // 验证金额正确性 if (amount.equals("0.00")) { throw new IllegalArgumentException("金额不能为零."); } Matcher matcher = AMOUNT_PATTERN.matcher(amount); if (! matcher.find()) { throw new IllegalArgumentException("输入金额有误."); } String integer = matcher.group(1); // 整数有些 String fraction = matcher.group(2); // 小数有些 String result = ""; if (! integer.equals("0")) { result = integer2rmb(integer) UNITS[0]; // 整数有些 } if (fraction.equals("00")) { result = UNITS[3]; // 添加[整] } else if (fraction.startsWith("0") http://www.gookp11.com