标签:
/** * 将数字转换成对应的汉字 * * @param number * 数字 * @return 对应的汉字 */ public static String intToChinese(int number) { char[] val = String.valueOf(number).toCharArray(); int len = val.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { int n = Integer.valueOf(val[i] + ""); boolean isZero = n == 0; String unit = units[(len - 1) - i]; if (isZero) { if (i != len - 1 && i != 0 && '0' != val[i + 1]) { sb.append(numArray[n]); } } else { sb.append(numArray[n]); sb.append(unit); } } return sb.toString(); } /** * 将double类型转换为汉字 * * @param number * double类型数据 * @return 对应的汉字 */ public static String doubleToChinese(double number) { String numberStr = String.valueOf(number); int decIndex = numberStr.indexOf("."); int integer = Integer.valueOf(numberStr.substring(0, decIndex)); String dec = numberStr.substring(decIndex + 1); return intToChinese(integer) + "." + decimalToChinese(dec); } /** * 将小数部分转换为汉字 * * @param decimal * 小数部分 * @return 对应的汉字 */ private static String decimalToChinese(String decimal) { char[] val = decimal.toCharArray(); int len = val.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { int n = Integer.valueOf(val[i] + ""); sb.append(numArray[n]); } return sb.toString(); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u010142437/article/details/47131581