自己写的,C#版,把数字转换为人民币大写
public static string GetNumber2CN(double number){
StringBuilder cnStr = new StringBuilder();
string CnNumber = "零壹贰叁肆伍陆柒捌玖";
string CnUnit = "分角元十百千万十百千亿十百千万";
string numStr = number.ToString("#0.00").Replace(".", "");
for (int i = 0; i < numStr.Length; i++)
{
int num = int.Parse(numStr.Substring(i, 1));
cnStr.Append(CnNumber.Substring(num, 1) + CnUnit.Substring(numStr.Length - i - 1, 1));
}
while (Regex.IsMatch(cnStr.ToString(), "零零|零十|零百|零千|零万|零亿|亿万"))
{
cnStr = cnStr.Replace("零十", "零");
cnStr = cnStr.Replace("零百", "零");
cnStr = cnStr.Replace("零千", "零");
cnStr = cnStr.Replace("零万", "万");
cnStr = cnStr.Replace("零亿", "亿");
cnStr = cnStr.Replace("零零", "零");
cnStr = cnStr.Replace("亿万", "亿零");
}
cnStr = cnStr.Replace("零元", "元").Replace("零角", "").Replace("零分", "");
return cnStr.ToString().StartsWith("元") ? cnStr.ToString().Substring(1) : cnStr.ToString();
}
如果哪位能完善的更好,贴出来分享一下
呵呵,又编辑了以下标题,方便大家查询,下面也跟了完善版
[[it] 本帖最后由 zhukuntang 于 2008-11-1 10:50 编辑 [/it]]