class RMB {
private static final char[] data = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾' };
private static final char[] units = { '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟','万' };
public static String convert(int money) {
StringBuffer sbf = new StringBuffer();
int unit = 0;
while (money != 0) {
sbf.insert(0, units[unit++]);
int number = money % 10;
char d = data[number];
if(d=='零'&&sbf.length()>0&&unit>1){
sbf.deleteCharAt(0);
}
sbf.insert(0, d);
money /= 10;
}
String moneyStr = sbf.toString();
while (moneyStr.indexOf("零零")>0) {
moneyStr = moneyStr.replaceAll("零零", "零");
}
return moneyStr.replace("零圆", "");
}
}
转载于:https://my.oschina.net/robslove/blog/276844