Java代码
- public class ChinaNumber
- {
- private static String[] CH = { "", "", "拾", "佰", "仟", "万", "", "", "", "亿", "", "", "", "兆" };
- private static String[] CHS_NUMBER={ "零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
- /**
- * 传入数字金额字符串,返回数字金额对应的中文大字与读法
- *
- * @param money
- * 金额字符串
- * @return 金额中文大写
- */
- public static String getCHSNumber(String money)
- {
- String chs = "";
- String tmp_int = money.substring(0, money.indexOf("."));
- String tmp_down = money.substring(money.indexOf(".") + 1, money.length());
- char[] tmp_int_char = tmp_int.toCharArray();
- String[] tmp_chs = new String[tmp_int_char.length];
- int tab = 0;
- for (int i = 0; i < tmp_int_char.length; i++)
- {
- tab = tmp_int_char.length - i - 1;
- if (tmp_int_char.length <= 5)
- {
- tmp_chs[tab] = CHS_NUMBER[(int) Float.parseFloat(tmp_int_char[i] + ".0")];
- if (!tmp_chs[tab].equals("零"))
- {
- // tmp_int_char.length - i 为数字所在的位数
- chs = chs + tmp_chs[tab] + CH[tmp_int_char.length - i];
- } else
- { // 当数字中有零时就在后加上零,如果超过1个以上的零也只加一个零
- if (!chs.endsWith("零") && tab != 0)
- {
- chs = chs + tmp_chs[tab];
- } else if (chs.endsWith("零") && tab == 0)
- {
- chs = chs.substring(0, chs.length() - 1);
- }
- }
- }