人民幣小寫轉大寫

來源:互聯網
上載者:User
  1.  /**
  2.       * 小寫金額轉成大寫。
  3.       * @param input
  4.       * @return
  5.       */
  6.      public static String numtochinese(String input){ 
  7.         String s1="零壹貳三肆伍陸柒捌玖"; 
  8.         String s4="分角整元拾佰仟萬拾佰仟億拾佰仟"; 
  9.         String temp=""; 
  10.         String result=""; 
  11.         if (input==null) return "輸入字串不是數字串只能包括以下字元(′0′~′9′,′.′),輸入字串最大隻能精確到仟億,小數點只能兩位!"; 
  12.         temp=input.trim(); 
  13.         float f; 
  14.         try{ 
  15.         f=Float.parseFloat(temp); 
  16.         }catch(Exception e){return "輸入字串不是數字串只能包括以下字元(′0′~′9′,′.′),輸入字串最大隻能精確到仟億,小數點只能兩位!";} 
  17.         int len=0; 
  18.         if (temp.indexOf(".")==-1) len=temp.length(); 
  19.         else len=temp.indexOf("."); 
  20.         if(len>s4.length()-3) return("輸入字串最大隻能精確到仟億,小數點只能兩位!"); 
  21.         int n1,n2=0; 
  22.         String num=""; 
  23.         String unit=""; 
  24.         for(int i=0;i<temp.length();i++){ 
  25.         if(i>len+2){break;} 
  26.         if(i==len) {continue;} 
  27.         n1=Integer.parseInt(String.valueOf(temp.charAt(i))); 
  28.         num=s1.substring(n1,n1+1); 
  29.         n1=len-i+2; 
  30.         unit=s4.substring(n1,n1+1); 
  31.         result=result.concat(num).concat(unit); 
  32.         } 
  33.         if ((len==temp.length()) ||(len==temp.length()-1)) result=result.concat("整"); 
  34.         if (len==temp.length()-2) result=result.concat("零分"); 
  35.         return result; 
  36.         } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.