人民幣轉換大寫

一、spa

public class RenMinBi {
    //數字
    private static final char[] data = new char[] {'零', '壹', '貳', '叄', '肆',
        '伍', '陸', '柒', '捌', '玖'};
    //單位
    private static final char[] units = new char[] {'元', '拾', '佰', '仟', '萬',
        '拾', '佰', '仟', '億'};
     static int count = 0;
    
    public String change(String str) {
        StringBuffer sb = new StringBuffer();
        String moneystr = str.substring(1);
        Integer money = Integer.parseInt(moneystr);
        while (money!=0) {
            int yushu = money%10;
            sb.insert(0,units[count++]);
            sb.insert(0, data[yushu]);
            money = money/10;
        }
        return sb.toString();
    }
}
相關文章
相關標籤/搜索