#region 将数字转化为中文…… /// <summary> /// 数字转中文 /// </summary> private const string DXSZ = "零壹贰叁肆伍陆柒捌玖", DXDW1 = "仟佰拾", DXDW2 = "兆亿萬"; /// <summary> /// 整数转换为中文 /// </summary> /// <param name="number"></param> /// <returns></returns> public static string ToChineseNumber(long number) { try { long temp = 0; int pleng = number.ToString().Length - 1; string strNumber = ""; if (number.ToString().Length == 1) strNumber = DXSZ.Substring(Convert.ToInt32(number), 1); else if (pleng <= 3) { temp = number / (long)(System.Math.Pow(10, pleng)); if (temp > 0) strNumber = ToChineseNumber(temp) + DXDW1.Substring(DXDW1.Length - pleng, 1); number = number % (long)(System.Math.Pow(10, pleng)); if (number > 0) { if (pleng != number.ToString().Length) strNumber = strNumber + DXSZ.Substring(0, 1); strNumber = strNumber + ToChineseNumber(number); } } else if (pleng <= 19) { int logleng = (int)Math.Log(Convert.ToInt32(pleng / 4), 2); temp = number / (long)(System.Math.Pow(10000, System.Math.Pow(2, logleng))); if (temp > 0) strNumber = strNumber + ToChineseNumber(temp) + DXDW2.Substring(DXDW2.Length - logleng - 1, 1); number = number % (long)(System.Math.Pow(10000, System.Math.Pow(2, logleng))); if (number > 0) { if (pleng - temp.ToString().Length + 1 != number.ToString().Length) strNumber = strNumber + DXSZ.Substring(0, 1); strNumber = strNumber + ToChineseNumber(number); } } return strNumber; } catch { throw new OverflowException("数据异常。"); } } #endregion #region 将货币转换为中文…… public static string ToChineseCurrency(decimal currency) { string strCurrency = "", decimalCurrency = "", strDecimalCurrency=""; long longCurrency = 0; if (currency.ToString("0.00").IndexOf('.') > 0) { string[] arryStr = currency.ToString("0.00").Split('.'); longCurrency = long.Parse(arryStr[0]); decimalCurrency = arryStr[1]; } else { longCurrency = (long)currency; } if (longCurrency > 0) strCurrency = ToChineseNumber(longCurrency)+"元"; if (decimalCurrency!="") { string currencyDW = "角分"; for (int i = 0; i < decimalCurrency.Length; i++) { int number = Convert.ToInt32(decimalCurrency.Substring(i, 1)); if (number > 0) { strDecimalCurrency += DXSZ.Substring(Convert.ToInt32(number), 1) + currencyDW.Substring(i, 1); } } } if (strDecimalCurrency == "") strCurrency += "整"; else strCurrency += strDecimalCurrency; return strCurrency; } #endregion