怎么实现金额转换,将阿拉伯数字金额转换成中国传统形式,例如1011变成一千零一拾一元整?
package test; public class Rmb { private static final char[] data = {'零','壹','贰','叄','肆','伍','陆','柒','捌','玖'}; private static final char[] units = {'元','拾','佰','仟','万','拾','佰','仟','亿'}; public static String convert(int money){ StringBuffer sbf = new StringBuffer(); int uint = 0; while(money != 0){ sbf.insert(0,units[uint++]); sbf.insert(0,data[money%10]); money = money/10; } //去零 return sbf.toString().replaceAll("零[拾佰仟]","零").replaceAll("零+万","万").replaceAll("零+元","元").replaceAll("零+","零"); } public static void main(String[] args){ Rmb rmb = new Rmb(); System.out.println(rmb.convert(1011)); //输出壹仟零壹拾壹元 } }
魔由心生,有万境纵横,无一道清静,无量寿佛!