一个将阿拉伯数字转换成中文大写的最简单算法

作者:网络 来源:佚名 更新时间:2008-11-23 17:18:58 点击:
国内最大的酷站演示中心!
代码如下:

//加到类的定义部分
private static string[] cstr={"零","壹","贰","叁","肆", "伍", "陆","柒","捌","玖"};
private static string[] wstr={"","","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟"};
//数字必须在12位整数以内的字符串
//调用方式如:label1.text=convertint("数字字符串");

public string convertint(string str)
{
int len=str.length;
int i;
string tmpstr,rstr;
rstr="";
for(i=1;i<=len;i++)
{
tmpstr=str.substring(len-i,1);
rstr=string.concat(cstr[int32.parse(tmpstr)]+wstr[i],rstr);
}
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+="圆整";
return rstr;
}