public class RenMingBi {
private static final char[] data = new char[]{
'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'
};
private static final char[] units = new char[]{
'元','拾','佰','仟','万','拾','佰','仟','亿'
};
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(convert(110000100));
}
/*
public static String convert(int money)
{
StringBuffer sb = new StringBuffer();
int unit = 0;
while(money!=0)
{
sb.insert(0,units[unit++]);
int number = money%10;
sb.insert(0, data[number]);
money /= 10;
}
return sb.toString().replaceAll("零[拾佰仟]","零").replaceAll("零{4}万","零").replaceAll("零+","零").replaceAll("零万","万").replaceAll("零元","元");
}*/
public static String convert(int money) {
StringBuilder sb = new StringBuilder();
int unit = 0;
while(money != 0) {
sb.append(units[unit++]);
int num = money%10;
sb.append(data[num]);
money /= 10;
}
return sb.reverse().toString().replaceAll("零[拾佰仟]","零").replaceAll("零{4}万","零").replaceAll("零+","零").replaceAll("零万","万").replaceAll("零元","元");
}
}
金额转换——阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)
最新推荐文章于 2020-09-05 01:27:58 发布