首页 > 开发 > 综合 > 正文

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

2024-07-21 02:30:22
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!
代码如下:

//加到类的定义部分
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;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表