C# 金额数字转中文的方法
/// <summary> /// 金额数字转大写(带小数点) /// </summary> public static string PriceToCn(decimal price) { //数字转大写 string[] n = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; string[] d = { "", "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" }; //不同位置的数字要加单位 List<string> needReplace = new List<string> { "零拾", "零佰", "零仟", "零万", "零亿", "亿万", "零元", "零零", "零角", "零分" }; List<string> afterReplace = new List<string> { "零", "零", "零", "万", "亿", "亿", "元", "零", "零", "" }; string e = price % 1 == 0 ? "整" : ""; //金额是整数,加一个“整”结尾 string re = ""; int a = (int)(price * 100); int k = 1; while (a != 0) { //初步转换大小写 re = n[a % 10] + d[k] + re; a = a / 10; k = k < 11 ? k + 1 : 4; } string need = needReplace.Where(tb => re.Contains(tb)).FirstOrDefault<string>(); while (need != null) { int i = needReplace.IndexOf(need); re = re.Replace(needReplace[i], afterReplace[i]); need = needReplace.Where(tb => re.Contains(tb)).FirstOrDefault<string>(); }//循环排除特殊情况 re = re == "" ? "零元" : re + e; return re; }