public static string ToUpperChineseRmb(decimal num, UtilityMath.RoundingMode roundMode) { //if (num < 0 || num > 9999999999999.99M) //{ // throw new ArgumentOutOfRangeException("金额应为正数,小于(且不等于)10万亿"); //} //string zheng = "整"; //string shuzi = "零壹贰叁肆伍陆柒捌玖"; //string danwei = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //string sourceNum = string.Empty; //#region Round -> ToString //switch (roundMode)//将num取绝对值并四舍五入取2位小数,然后乘100并转换成字符串形式 //{ // case UtilityMath.RoundingMode.Rounding_4she5ru: // sourceNum = ((long)(UtilityMath.Round(num, 2) * 100)).ToString(); // break; // case UtilityMath.RoundingMode.Rounding_4she6ru5chengshuang: // sourceNum = ((long)(System.Math.Round(num, 2) * 100)).ToString(); // break; //} //#endregion //char[] source = sourceNum.ToCharArray(); //StringBuilder sb = new StringBuilder(sourceNum); //for (int i = sourceNum.Length - 1; i >= 0; i--) //{ // sb.Replace(sb[i], shuzi[Convert.ToInt16(sb[i].ToString())], i, 1); //} //int z = 0; //while (!(sb.Length - z * 2 <= 0)) //{ // sb.Insert(sb.Length - z * 2, danwei[danwei.Length - 1 - z]); // z++; //} //return sb.ToString(); return ToUpperChineseRmb(num, 0); }
public static string ToUpperChineseRmb(string numString, UtilityMath.RoundingMode roundMode) { decimal num; if (decimal.TryParse(numString, out num)) { return ToUpperChineseRmb(num, roundMode); } else { throw new ArgumentException("非数字的字符串。"); } }