数字格式化成大写数字方法
原创
©著作权归作者所有:来自51CTO博客作者pyzheng的原创作品,请联系作者获取转载授权,否则将追究法律责任
@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);
}