数字格式化成大写数字方法
http://my.oschina.net/liygheart/blog/488554
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Java代码 @Test public void testno2hz() { no2hz(10010); } public void no2hz(int no) { String[] str1 = new String[]{"零","一","二","三","四","五","六","七","八","九"}; String[] str2 = new String[]{"十", "百", "千", "万"}; String sno = String.valueOf(no); int[] nos = new int[sno.length()]; for (int a = 0; a < sno.length(); a++) { String ss = sno.substring(a, a + 1); nos[a] = Integer.parseInt(ss); } String s = ""; for (int i = 0; i < sno.length(); i++) { s+=str1[nos[i]]; s = s.replace("零零", "零"); int a = sno.length() - i - 2; if(sno.length() > 1 && a >= 0 && !str1[nos[i]].equals(str1[0])) { s+=str2[a]; } } if(s.substring(s.length()-1, s.length()).equals(str1[0])) { s=s.substring(0, s.length()-1); } System.out.println(s); } |