private static final char[] data = new char[]{'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};
private static final char[] unit = new char[]{'元','拾','佰','仟','万','拾','佰','仟','亿'};
private static String convert(int money){
StringBuffer sb = new StringBuffer();
int index = 0;
while(money!=0) {
sb.insert(0,unit[index++]); //0脚标,插入一个单位
int num = money%10; //某单位对应的数字
sb.insert(0, data[num]); //0脚标,插入一个数字对应的汉字
//System.out.println(sb.toString());//打印添加单位的过程
money /= 10; //其余单位的数字。
}
return sb.toString().replaceAll("零[拾佰仟]","零").replaceAll("零+","零").replaceAll("零万","万").replaceAll("零元","元"); |