金额转换,阿拉伯数字转换成中国传统形式
金额转换,阿拉伯数字转换成中国传统形式。
例如:101000001010 转换为 壹仟零壹拾亿零壹仟零壹拾圆整
这个题不会,找了一个 ,但是 输入长了 比如101000001010 就报错了
求大侠指点
public class Test{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//输出测试
System.out.println(getString(405356221));
System.out.println(getString(11000001010));
}
//定义两个数组 给数字做单位
public static String[] cn={"仟","佰","拾","万","仟","佰","拾","亿","仟","佰","拾","万","仟","佰","拾","圆整"};
public static String[] number={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
public static String getString(int n)
{
String money=""+n;
//超过长度提醒
if(money.length()>cn.length)
throw new IllegalArgumentException("人民币超出计算范围,请重新输入!");
//定义返回 字符串
String str="";
//使用for循环 匹配每个位数上的单位,以及大小写
for(int i=0;i<money.length();i++)
str+=number[Integer.parseInt(""+money.charAt(i))]+cn[cn.length-money.length()+i];
return str;
}
}
来自:http://bbs.itheima.com/forum.php?mod=viewthread&tid=44453&highlight=