zoukankan      html  css  js  c++  java
  • 货币之间的大小写转换

    package org.com.base;

    import java.util.Scanner;

    public class Test {
     public String numtochinese(String input){
         String s1="零壹贰叁肆伍陆柒捌玖";
         String s4="分角整元拾佰仟万拾佰仟亿拾佰仟";
         String temp="";
         String result="";
         if (input==null) return "输入字串不是数字串只能包括以下字符('0'~'9','.'),输入字串最大只能精确到仟亿,小数点只能两位!";
         temp=input.trim();//清除货币字符串的前后空格
         float f;
         try{
             f=Float.parseFloat(temp);//将货币转换为Float类型的

         }catch(Exception e){
          return "输入字串不是数字串只能包括以下字符('0'~'9','.'),输入字串最大只能精确到仟亿,小数点只能两位!";
       }
         int len=0;
         if (temp.indexOf(".")==-1){ //判断小数点之后有没有 数字
          len=temp.length();
         }
         else{
          len=temp.indexOf(".");
         }
         if(len>s4.length()-3) {
          return("输入字串最大只能精确到仟亿,小数点只能两位!");
         }
         int n1,n2=0;
         String num="";
         String unit="";

         for(int i=0;i<temp.length();i++){
          if(i>len+2){break;}
          if(i==len) {continue;}
            n1=Integer.parseInt(String.valueOf(temp.charAt(i)));
            num=s1.substring(n1,n1+1);
            n1=len-i+2;
            unit=s4.substring(n1,n1+1);
            result=result.concat(num).concat(unit);
         }
         if ((len==temp.length())||(len==temp.length()-1)) result=result.concat("整");
         if (len==temp.length()-2) result=result.concat("零分");
         return result;
       } 
     public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String str = sc.next();
      Test test= new Test();
      String money = test.numtochinese(str);
      System.out.println(str+"--------转换为---------"+money);
     }
    }

  • 相关阅读:
    存储过程分页,前台应用范例repeater分页
    引用真正分页控件(与存储过程联合使用)页面
    分页存储过程repeater分页
    查找DetailsView1数据控件中的数据
    c#读取文件
    SQL触发器实例讲解
    TreeView节点选中问题
    C# 实现版本自动更新
    .Net那点事儿系列:C#操作Xml:通过XmlDocument读写Xml文档
    Linq学习笔记
  • 原文地址:https://www.cnblogs.com/huangchuansen/p/huangchuansen.html
Copyright © 2011-2022 走看看