public class Demo03 {
public static void main(String[] args) {
//金额大小写转换
float money = 1234.0f;
int m1,m2,m3,m4,m5,m6,temp;
temp = (int) (money*100);
System.out.println(money);
m1 = temp % 1000000/100000;
m2 = temp % 100000/10000;
m3 = temp % 10000/1000;
m4 = temp % 1000/100;
m5 = temp % 100/10;
m6 = temp % 10;
char c1,c2,c3,c4,c5,c6;
c1 = transe(m1);
c2 = transe(m2);
c3 = transe(m3);
c4 = transe(m4);
c5 = transe(m5);
c6 = transe(m6);
String str = "";
if(m1!=0){
str += c1+"千";
}
if(m2!=0){
str += c2+"百";
}
if(m1!=0 && m2==0 && (m3!=0||m4!=0)){
str += "零";
}
if(m3!=0){
str += c3 + "十";
}
if(m4!=0){
str += c4;
}
if(m5==0&&m6==0){
str+="整";
}
if(m5!=0){
str = c5 + "角";
}
if(m5==0 && m6 !=0){
str = "零";
}
if(m6 !=0){
str += c6 + "分";
}
System.out.println(str + "\n");
}
public static char transe(int m){
char r = ' ';
switch (m) {
case 0:
r = '零';
break;
case 1:
r = '壹';
break;
case 2:
r = '贰';
break;
case 3:
r = '叁';
break;
case 4:
r = '肆';
break;
case 5:
r = '伍';
break;
case 6:
r = '陆';
break;
case 7:
r = '柒';
break;
case 8:
r = '捌';
break;
case 9:
r = '玖';
break;
}
return r;
}
}
public static void main(String[] args) {
//金额大小写转换
float money = 1234.0f;
int m1,m2,m3,m4,m5,m6,temp;
temp = (int) (money*100);
System.out.println(money);
m1 = temp % 1000000/100000;
m2 = temp % 100000/10000;
m3 = temp % 10000/1000;
m4 = temp % 1000/100;
m5 = temp % 100/10;
m6 = temp % 10;
char c1,c2,c3,c4,c5,c6;
c1 = transe(m1);
c2 = transe(m2);
c3 = transe(m3);
c4 = transe(m4);
c5 = transe(m5);
c6 = transe(m6);
String str = "";
if(m1!=0){
str += c1+"千";
}
if(m2!=0){
str += c2+"百";
}
if(m1!=0 && m2==0 && (m3!=0||m4!=0)){
str += "零";
}
if(m3!=0){
str += c3 + "十";
}
if(m4!=0){
str += c4;
}
if(m5==0&&m6==0){
str+="整";
}
if(m5!=0){
str = c5 + "角";
}
if(m5==0 && m6 !=0){
str = "零";
}
if(m6 !=0){
str += c6 + "分";
}
System.out.println(str + "\n");
}
public static char transe(int m){
char r = ' ';
switch (m) {
case 0:
r = '零';
break;
case 1:
r = '壹';
break;
case 2:
r = '贰';
break;
case 3:
r = '叁';
break;
case 4:
r = '肆';
break;
case 5:
r = '伍';
break;
case 6:
r = '陆';
break;
case 7:
r = '柒';
break;
case 8:
r = '捌';
break;
case 9:
r = '玖';
break;
}
return r;
}
}