例:将整型数字转换为对应的数字大写,999对应为九百九十九;如果按照每四位数进行转换或许效率更高,更准确!
public static string RevertNumToBig(int num) { string bigNum = string.Empty, bigNumPart = string.Empty; //int g = 0, s = 0, b = 0, q = 0, w = 0; string[] bigNumArr = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" }; string[] levels = new string[] { "", "十", "百", "千", "万", "亿" }; int pow = 0, lvNum = 0; while ((double)num >= System.Math.Pow(10, pow)) { pow++; } while (pow > 0) { if (num > 0 || pow > 4) {//末位为零时不显示 lvNum = num / (int)(System.Math.Pow(10, pow - 1)); if (lvNum > 0 || (pow < 8 && !bigNum.EndsWith("零")))//去除多余显示的'零' bigNum += bigNumArr[lvNum]; if (pow > 4 && pow % 4 == 1) { if (!bigNum.EndsWith("亿"))//当万级都为0时跳过 bigNum += levels[pow % 4 + 4 - pow / 4 % 2];//每4位获得最大的数量级 } else { if (lvNum > 0) bigNum += levels[(pow % 4 == 0) ? 3 : (pow % 4 - 1)];//获得每位的数量级 } } num -= (int)(System.Math.Pow(10, pow - 1)) * lvNum;//减去已计算的位数 pow--; } if (bigNum.Contains("亿零万")) bigNum = bigNum.Replace("零万", string.Empty); else if (bigNum.Contains("零万")) bigNum = bigNum.Replace("零万", "万"); return bigNum; }