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));
}
}
人民币小写转大写算法
最新推荐文章于 2021-01-22 21:22:01 发布