日期:2014-05-18  浏览次数:20649 次

****某软件公司的面试题! ¥4280如何转成文字四千八百元,测测大家的逻辑!
数字多少无所谓,主要是方法

------解决方案--------------------
你在本版搜索一下,有你想要的
------解决方案--------------------
考虑中文以四位做进制就不难了
------解决方案--------------------
以前做了一下午搞出来了
难点是0多的时候 还有小数
------解决方案--------------------
用C#改的,比较简单,但不知道会不会出问题,请大家测一下


public class C {
private String[] cstr = {
"零 ", "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 "};
private String[] wstr = {
" ", "拾 ", "佰 ", "仟 ", "萬 ", "拾 ", "佰 ", "仟 ", "億 ", "拾 ", "佰 ", "仟 "};
public String ConvertInt(String str) {
int len = str.length();
int i;
String rstr,tmpstr= " ";
for (i = len-1;i> =0; i--) {
tmpstr=this.getChinese(str.charAt(i))+wstr[len-i-1]+tmpstr;
}
rstr=tmpstr.toString();
rstr = rstr.replace( "拾零 ", "拾 ");
rstr = rstr.replace( "零拾 ", "零 ");
rstr = rstr.replace( "零佰 ", "零 ");
rstr = rstr.replace( "零仟 ", "零 ");
rstr = rstr.replace( "零萬 ", "萬 ");
for (i = 1; i <= 6; i++) {
rstr = rstr.replace( "零零 ", "零 ");
}
rstr = rstr.replace( "零萬 ", "零 ");
rstr = rstr.replace( "零億 ", "億 ");
rstr = rstr.replace( "零零 ", "零 ");
rstr = rstr.endsWith( "零 ")?rstr.substring(0,rstr.length()-1):rstr;
return rstr;
}
private String getChinese(char n){
int k=Integer.parseInt(String.valueOf(n));
return cstr[k];
}
public static void main(String[] args) {
C c=new C();
System.out.println(c.ConvertInt( "90090 "));
}
}