import java.util.Scanner;
public class Num
{
public Num() {}
static String []bigNum={"零","一","二","三","四","五","六","七","八","九"};
static String getNUM(String str)
{
int t=Integer.parseInt(str);
return bigNum[t];
}
public static void main(String[] args)
{
try
{
String strbig=new String("");
System.out.print("请输入数字:");
Scanner sc=new Scanner(System.in);
long num=sc.nextLong();
String temp=String.valueOf(num);
int b=temp.indexOf(".");
int s=temp.length()-(b+1);
int j=b;
for (int i =0; i<b;i++) {
strbig+=getNUM(temp.substring(i,i+1));
j--;
}
temp=temp.substring(b+1,temp.length());
for (int i = 0; i < s; i++)
{
strbig+=getNUM(temp.substring(i,i+1));
}
System.out.println("转换结果:"+strbig);
}
catch(Exception ex)
{
System.out.println("请输入整数");
}
}
}
B. 用java把阿拉伯数字转换成中文数字,怎么做
有个简单的转换,支持10亿以内
public class Test {
public static void test(int d) {
// String[] str = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String[] str = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
// String ss[] = new String[] { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" };
String ss[] = new String[] { "个", "十", "百", "千", "万", "十", "百", "千", "亿" };
String s = String.valueOf(d);
System.out.println(s);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
String index = String.valueOf(s.charAt(i));
sb = sb.append(str[Integer.parseInt(index)]);
}
String sss = String.valueOf(sb);
int i = 0;
for (int j = sss.length(); j > 0; j--) {
sb = sb.insert(j, ss[i++]);
}
System.out.println(sb);
}
public static void main(String[] args) {
test(3213);
test(912321321);
}
}
结果
不想要“个”的话就把 ss[] 数组中的“个”改成空
不过毕竟是机械的转换,有零的话不太符合语言习惯