输入:123L
输出:壹佰贰拾叁
代码:
import java.util.ArrayList;
import java.util.List;
public class NumT {
public static void main(String[] args) {
long num = 2010030L;
System.out.println(readNum(num));
}
private static String readNum(long num){
String s_num=num+"";
String s = "";
int numLen = s_num.length();
List<String> ls = new ArrayList<>();
if(numLen>16){
String hz = "乘以拾的"+num2str((numLen-1)+"")+"次方";
s=num2floatstr(s_num);
s=s+hz;
}else{
if(numLen%4==0){
int z = numLen/4;
for(int i=0;i<z;i++){
ls.add(s_num.substring(numLen-4*(i+1), numLen-4*i));
}
}else{
int z = numLen/4+1;
int lastSize = numLen%4;
int i=0;
for(;i<z-1;i++){
ls.add(s_num.substring(numLen-4*(i+1), numLen-4*i));
}
ls.add(s_num.substring(0,lastSize));
}
String[] dw = {"","万","亿","万亿"};
for(int i=0;i<ls.size();i++){
if(!ls.get(i).equals("0000")){
s=num2str(ls.get(i))+dw[i]+s;
}
}
}
return s;
}
private static String num2str(String str){
int size = str.length();
String[] dw = {"","拾","佰","仟"};
String s="";
for(int i=size;i>0;i--){
switch(str.charAt(i-1)){
case '0':s="零"+s;break;
case '1':s="壹"+dw[size-i]+s;break;
case '2':s="贰"+dw[size-i]+s;break;
case '3':s="叁"+dw[size-i]+s;break;
case '4':s="肆"+dw[size-i]+s;break;
case '5':s="伍"+dw[size-i]+s;break;
case '6':s="陆"+dw[size-i]+s;break;
case '7':s="柒"+dw[size-i]+s;break;
case '8':s="捌"+dw[size-i]+s;break;
case '9':s="玖"+dw[size-i]+s;break;
}
}
s = s.replaceAll("零{1,}", "零");
s = s.replaceAll("拾零", "拾");
return s;
}
private static String num2floatstr(String str){
int size = str.length();
String s = "";
for(int i=1;i<=size;i++){
switch(str.charAt(i-1)){
case '0':s=s+"零";break;
case '1':s=s+"壹";break;
case '2':s=s+"贰";break;
case '3':s=s+"叁";break;
case '4':s=s+"肆";break;
case '5':s=s+"伍";break;
case '6':s=s+"陆";break;
case '7':s=s+"柒";break;
case '8':s=s+"捌";break;
case '9':s=s+"玖";break;
}
if(i==1){
s = s+"点";
}
}
return s;
}
}