天天看點

金額轉換

12.金額轉換,阿拉伯數字的金額轉換成中國傳統的形式如:(¥1011)->(一千零一拾一進制整)輸出。

去零的代碼:

    returnsb.reverse().toString().replaceAll("零[拾佰仟]","零").replaceAll("零+萬","萬").replaceAll("零+元","元").replaceAll("零+","零");

public class RenMingBi {
 
       /**
        * @param args add by zxx ,Nov 29, 2008
        */
       private static finalchar[] data = new char[]{
                     '零','壹','貳','叁','肆','伍','陸','柒','捌','玖'
              };
       private static finalchar[] units = new char[]{
              '元','拾','佰','仟','萬','拾','佰','仟','億'
       };
       public static voidmain(String[] args) {
              // TODOAuto-generated method stub
              System.out.println(
                            convert(135689123));
       }
 
       public static Stringconvert(int money)
       {
              StringBuffersbf = new StringBuffer();
              int unit = 0;
              while(money!=0)
              {
                     sbf.insert(0,units[unit++]);
                     intnumber = money%10;
                     sbf.insert(0,data[number]);
                     money/= 10;
              }
 
              returnsbf.toString();
       }
}
           

繼續閱讀