人民币小写转大写算法

import java.math.*;
import java.util.*;
public class a

{
    static int Pw(double a)  //判断位数
    {
        int count=0;
        for(int i=1;;i*=10)
        if(a>i) count++;
        else break;
        return count;
    }
    static String anl(double a)
    {
        double xiaoshuh=a%1.0+0.001;
        String[] shul={"","壹","贰","叁","肆","伍","陸","柒","捌","玖"};
        String xiaos="";
        String[] zhengs={"","",""};
        int zhshubf=(int)a;
        int ws=Pw(a);
        if((int)(xiaoshuh*10)!=0)
            xiaos+=shul[(int)(xiaoshuh*10)]+"角";
        if((int)(xiaoshuh*100%10)!=0)
            xiaos+=shul[(int)(xiaoshuh*100%10)]+"分";
        for(int i=0;i<=ws/4;i++)
        {   
            int z;
            if(ws>=(i+1)*4)
            z=4;
            else z=ws%4;
            String[] dw={"","万","亿"};                           
            double chuls=(double)(zhshubf/(Math.pow(10000.0, i+1))%1.0+0.00001);
                System.out.println("第"+(i+1)+"次   chuls="+chuls);
            switch(z)
            {
                case 4: if((int)(chuls*10)!=0) zhengs[i]+=shul[(int)(chuls*10)]+"仟";
                case 3: if((int)(chuls*100%10)!=0) zhengs[i]+=shul[(int)(chuls*100%10)]+"百";
                case 2: if((int)(chuls*1000%10)!=0) zhengs[i]+=shul[(int)(chuls*1000%10)]+"拾";
                case 1: if((int)(chuls*10000%10)!=0) zhengs[i]+=shul[(int)(chuls*10000%10)]+dw[i];              
            }
            System.out.println(zhengs[i]);
        }   
        if(a>0.0)   
            return zhengs[2]+zhengs[1]+zhengs[0]+"元"+xiaos;     
        else
            return xiaos;       
    }
    public static void main(String[] args)
    {
        double RMB;
        Scanner inn=new Scanner(System.in);
        System.out.print("请输入数字(小于十位):");
        RMB=inn.nextDouble();   
        System.out.println("大写:"+anl(RMB));         
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值