网上搜的都有问题,这个代码属于原创,代码简洁,支持小数点,若没有小数点,则为整
/// <summary> /// 将金额转换成大写 /// </summary> /// <param name="moneys">字符串金额</param> /// <returns></returns> public static string GetUpperMoney(string money) { int dotPos = money.IndexOf('.');//小数点位置 string moneyRight = dotPos > -1 ? (money + "00").Substring(dotPos + 1, 2) : "";//小数部分 if (dotPos > -1) { money = money.Substring(0, dotPos);//money取整 } string rtnStr = ""; string daxie = "元拾佰仟万亿"; string daxieZ = "零壹贰叁肆伍陆柒捌玖"; int moneyLen = money.Length; for (int i = 0; i < moneyLen; i++) { string nowStr = money.Substring(i, 1); string mn1 = daxieZ.Substring(Convert.ToInt32(nowStr), 1); int nowPos = moneyLen - i - 1; if (nowPos > 7) { if (nowPos == 8) { nowPos = 5; } else { nowPos = nowPos % 9 + 1; } } else if (nowPos > 4) { nowPos = nowPos % 5 + 1; } string mn2 = daxie.Substring(nowPos, 1); rtnStr = rtnStr + mn1 + mn2; } rtnStr = rtnStr.Replace("零仟", "零"); rtnStr = rtnStr.Replace("零佰", "零"); rtnStr = rtnStr.Replace("零拾", "零"); rtnStr = rtnStr.Replace("零零零", "零"); rtnStr = rtnStr.Replace("零零", "零"); rtnStr = rtnStr.Replace("零万", "万"); rtnStr = rtnStr.Replace("零亿", "亿"); if (dotPos > 0) { rtnStr = rtnStr + daxieZ.Substring(Convert.ToInt32(moneyRight.Substring(0, 1)), 1) + "角"; rtnStr = rtnStr + daxieZ.Substring(Convert.ToInt32(moneyRight.Substring(1, 1)), 1) + "分"; } else { rtnStr += "整"; } return rtnStr; }