import java.util.*;
public class RmbConvert {
public void convertToCapital(double money){
String[] capitalRmb=new String[14];
for(int i=0;i<capitalRmb.length;i++){
int j=(int)((money*100)%10);
money/=10;
switch(j){
case 0: capitalRmb[i]="零";break;
case 1:capitalRmb[i]="壹";break;
case 2:capitalRmb[i]="贰";break;
case 3:capitalRmb[i]="叁";break;
case 4:capitalRmb[i]="肆";break;
case 5:capitalRmb[i]="伍";break;
case 6:capitalRmb[i]="陆";break;
case 7:capitalRmb[i]="柒";break;
case 8:capitalRmb[i]="捌";break;
case 9:capitalRmb[i]="玖";break;
}
}
String[] str=new String[]{
"仟","百","拾","亿 ","仟","百","拾","万 ","仟","百","拾","元 ","角","分"
};
int init=0;
while(capitalRmb[capitalRmb.length-1-init]=="零"){
init++;
}
for(int i=init;i<str.length;i++){
if(capitalRmb[capitalRmb.length-1-i]=="零"&&str[i]!="角"&&str[i]!="分"){
System.out.print(capitalRmb[capitalRmb.length-1-i]);
}else
System.out.print(capitalRmb[capitalRmb.length-1-i]+str[i]);
}
}
public void convertToLower(String money){
char[] c=money.toCharArray();
double[] num=new double[c.length/2];
int j=0;
for(int i=0;i<c.length;i+=2){
double d=num.length-3-j;
switch(c[i]){
case '零':num[j++]=(0*Math.pow(10.0,d));break;
case '壹':num[j++]=(1*Math.pow(10.0,d));break;
case '贰':num[j++]=(2*Math.pow(10.0,d));break;
case '叁':num[j++]=(3*Math.pow(10.0,d));break;
case '肆':num[j++]=(4*Math.pow(10.0,d));break;
case '伍':num[j++]=(5*Math.pow(10.0,d));break;
case '陆':num[j++]=(6*Math.pow(10.0,d));break;
case '柒':num[j++]=(7*Math.pow(10.0,d));break;
case '捌':num[j++]=(8*Math.pow(10.0,d));break;
case '玖':num[j++]=(9*Math.pow(10.0,d));break;
}
}
double init=0;
for(int i=0;i<num.length;i++){
init+=num[i];
}
System.out.print(init);
}
public static void main(String[] args) {
System.out.println("please enter the lower momey");
RmbConvert rmb=new RmbConvert();
Scanner sca=new Scanner(System.in);
Double money=sca.nextDouble();
System.out.println("convert to Capital");
rmb.convertToCapital(money);
System.out.println();
System.out.println("convert to lower");
Scanner sc=new Scanner(System.in);
String str=sc.next();
rmb.convertToLower(str);
}
}
将一个数字转化成中文输出
最新推荐文章于 2023-04-12 07:31:41 发布