人民币数字转文字
package day01; /** * Created by sherry on 000019/3/19 14:27. */ public class RmbToChar { public static void main(String[] args) { /*输入要求:10000以内的小数,对于特殊情况未做判断*/ rmbToChar(15523.451); } private static void rmbToChar(double v) { String num = Double.toString(v); /*大写码表*/ String[] numberMap = {"零","壹","贰","叁","肆","伍","陆","柒","扒","玖"}; /*整数部分*/ String integerPart = num.substring(0,num.indexOf(".")); /*小数部分*/ String decimalsPart = num.substring(num.indexOf(".")+1); System.out.println(integerPart+"."+decimalsPart); char[] integerParts = integerPart.toCharArray(); char[] decimalsParts = decimalsPart.toCharArray(); for (int i = 0;i < integerParts.length;i++){ System.out.print(numberMap[Integer.parseInt(String.valueOf(integerParts[i]))]); switch (integerParts.length-i){ case 5: System.out.print("万"); break; case 4: System.out.print("仟"); break; case 3: System.out.print("佰"); break; case 2: System.out.print("拾"); break; default: System.out.print("元"); } } for (int i = 0;i < decimalsParts.length;i++){ System.out.print(numberMap[Integer.parseInt(String.valueOf(decimalsParts[i]))]); switch (i){ case 0: System.out.print("角"); break; case 1: System.out.print("分"); break; case 2: System.out.print("厘"); break; default: System.out.print("毫"); } } } }