哪位兄弟帮忙写段代码?

cnzjw 2004-09-20 04:05:39
就是将货币用中文大写表示的,比如12345678换成壹仟贰佰叁拾肆万伍仟陆佰柒拾捌元。

谢谢!
...全文
91 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
海天候 2004-09-20
-48 是把字符的ASC码转成对应的数组索引

回复
cnzjw 2004-09-20
偶把final String Units[]={"分","角","元","拾","佰","仟", //单位
"万","拾","佰","仟","亿","拾","佰","仟","兆","拾","佰","仟"};

中的"分","角","去掉后就正常了,不过这样也不能计算小数点后的币值了
(不要骂偶笨,偶素菜鸟嘛 -______________- )

谁有更好的法子吗?
回复
cnzjw 2004-09-20
老大,返回结果是:壹拾贰万叁仟肆佰伍拾陆元柒角
如果输入是12345678应该是 壹仟贰佰叁拾肆万伍仟陆佰柒拾捌 啊

另外可以解释一下results+=Numbers[buf.charAt(i-1)-48];中-48是什么意思吗?
回复
redlaputa 2004-09-20
public final class Replace{

public static String ChangeToBig(String CurrentNumber){
//输入CurrentNumber的数字格式为%*.**;
String results=new String("¥");
String temp = CurrentNumber;

final String Units[]={"分","角","元","拾","佰","仟", //单位
"万","拾","佰","仟","亿","拾","佰","仟","兆","拾","佰","仟"};

final String Numbers[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; //大写数

java.lang.StringBuffer buf=new java.lang.StringBuffer(); //处理后的字符串

char c;

for(int i=0;i<temp.length();i++){ //去掉小数点
c=temp.charAt(i);
if(c!='.')
buf.append(c);
}

for(int i=1;i<buf.length();i++){
results+=Numbers[buf.charAt(i-1)-48];
results+=Units[buf.length()-i];
}
return results;
}


}
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-20 04:05
社区公告
暂无公告