package com.blingbling.text;
public class test {
public String toChinese(String number) {
String resultString = "";
String s1[] = {"零","一","二","三","四","五","六","七","八","九"};
String s2[] = {"十","百","千","万","十","百","千","亿","十","百"};
int n = number.length();
for (int i = 0; i < n; i++) {
int num = number.charAt(i)-'0';//将输入数字字符转化为数字类型
if (num != 0&&i!=n-1) {
resultString +=s1[num]+s2[n-2-i];
}else if(num == 0&&i == n-1){
resultString+="";//取消整百之类的后面的零输出
}else {
resultString+=s1[num];
}
}
return resultString;
}
public static void main(String[] args) {
test one = new test();
String result = one.toChinese("128");
System.out.println("大写:" + result);
}
}
阿拉伯数字转大写
最新推荐文章于 2024-02-04 10:38:01 发布