人民币转换
1 package t0107; 2 3 public class Money { 4 5 private static final char[] data = new char[]{ 6 ‘零‘,‘壹‘,‘贰‘,‘叁‘,‘肆‘,‘伍‘,‘陆‘,‘柒‘,‘捌‘,‘玖‘, 7 }; 8 private static char[] units = new char[]{ 9 ‘元‘,‘拾‘,‘佰‘,‘仟‘,‘万‘,‘拾‘,‘佰‘,‘仟‘,‘亿‘, 10 }; 11 /** 12 * @param args 13 */ 14 public static void main(String[] args) { 15 System.out.println( convert(12123313) ); 16 17 } 18 19 public static String convert(int money){ 20 StringBuffer sbf = new StringBuffer(); 21 int unit = 0; 22 while(money != 0){ 23 24 sbf.insert(0, units[unit++]); 25 int number = money%10; 26 sbf.insert(0, data[number]); 27 money /= 10; 28 } 29 return sbf.toString(); 30 } 31 32 }
时间: 2024-08-05 09:48:03