- package com.coxon.finance.tool;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- public class ChinaNumber
- {
- private static String[] CH = { "", "", "拾", "佰", "仟" };
- private static String[] CHS_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- private static String[] CHS = { "万", "亿", "兆" };
- private static DecimalFormat df = new DecimalFormat("#########################0.0#");
- /**
- * 传入数字金额双精度型值,返回数字金额对应的中文大字与读法
- *
- * @param money
- * 金额
- * @return 金额中文大写
- */
- public static String transFormMoney(double money)
- {
- return transFormMoney(df.format(money));
- }
- /**
- * 传入数字金额浮点型值,返回数字金额对应的中文大字与读法
- *
- * @param money
- * 金额
- * @return 金额中文大写
- */
- public static String transFormMoney(float money)
- {
- return transFormMoney(df.format(money));
- }
- /**
- * 传入数字金额字符串,返回数字金额对应的中文大字与读法
- *
- * @param money
- * 金额字符串
- * @return 金额中文大写
- */
- public static String transFormMoney(String money)
- {
- String result = "";
- try
- {
- BigDecimal big = new BigDecimal(money);
- String[] t = null;
- try
- {
- t = big.toString().replace(".", ";").split(";");
- } catch (Exception e)
- {
- // 金额如果没有小数位时,也要加上小数位
- t = (big.toString() + ".0").replace(".", ";").split(";");
- }
- String[] intString = splitMoney(t[0]);
- String tmp_down = t[1];
- for (int i = 0; i < intString.length; i++)
- {
- result = result + count(intString[i]);
- if (i == intString.length - 2 || i == intString.length - 3 )
- continue;
- if (i != intString.length - 1)
- {
- result = result + CHS[intString.length - 2 - i];
- }
- }
- if (Integer.parseInt(tmp_down) == 0)
- {
- result = result + (intString[0].equals("0") ? "零元" : "元整");
- } else
- {
- result = result + (intString[0].equals("0") ? "" : tmp_down.startsWith("0") ? "元零" : "元")
- + getFloat(tmp_down);
- }
- } catch (Exception e)
- {
- return "你
- //该片段来自于http://www.codesnippet.cn/detail/030920135569.html
来源: http://www.codesnippet.cn/detail/030920135569.html