中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

把錢幣大寫 轉為 數字的Java代碼

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
把錢幣大寫 轉為 數字的Java代碼
import java.text.DecimalFormat;

public class Mm {
  /**
   * 轉億以下的
   * @param str
   * @return
   */  
  public static double b2s(String str){
      str=str.replaceAll("零", "");
      double sum=0;
      int index=str.indexOf("億");
      if (index>0){
              String temp=str.substring(0,index );
              str=str.substring(index+1);
              sum=sum+w(temp)*100000000;
      }
      index=str.indexOf("萬");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+w(temp)*10000;
      }
      index=str.indexOf("元");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+w(temp);
      }
      index=str.indexOf("角");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+str2num(temp)*0.1;
      }
      index=str.indexOf("分");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+str2num(temp)*0.01;
      }

      return sum;
  }
  /**
   * 大寫轉小寫
   * @param str
   * @return
   */
  public static int str2num(String str){
      String[] daxie={"壹","貳","叁","肆","伍","陸","柒","捌","玖"};
      int[] num={1,2,3,4,5,6,7,8,9};
      for (int i = 0; i < daxie.length; i++) {
            if ( str.equals( daxie[i] ) ) {
                 return num[i];
            }
          }
      return 0;
  }
  /**
   * @see 轉萬以下的
   * @param str
   * @return
   */
  public static double w(String str){
      double sum=0;
      int index=str.indexOf("仟");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+str2num(temp)*1000;
      }
      index=str.indexOf("佰");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+str2num(temp)*100;

      }
      index=str.indexOf("拾");
      if (index>0){
          String temp=str.substring(0,index );
          str=str.substring(index+1);
          sum=sum+str2num(temp)*10;
      }
      if (str.length()>0) {
          sum=sum+str2num(str) ;
      }
      return sum;
  }
  public static void main(String[] args) {
      DecimalFormat df=new DecimalFormat();
      df.setMinimumFractionDigits(2);
      df.setMaximumFractionDigits(2);
     System.out.println(df.format(b2s("壹仟萬零伍佰壹拾玖元捌角陸分") )); 
}

}

標簽: 代碼

版權申明:本站文章部分自網絡,如有侵權,請聯系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯系。

上一篇:計算JAVA源代碼行數的代碼

下一篇: 生成若干位數的隨機ID的Java工具類