/** * 将数字转换成相应的汉字 * * @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(); }