数字金额转成中文大字

/// <summary>
/// 将金额转换为汉字
/// </summary>
public class Converter
{

public static string Convert(double money)
{

string strMoney = money.ToString();

string[] arraryMoney = strMoney.Split('.');


//整数部分

StringBuilder builerInt = new StringBuilder();

if (arraryMoney != null)
{

string moneyInt = arraryMoney[0];

int lenOfInt = moneyInt.Length;

for (int i = 0; i < lenOfInt; i++)
{
//单位

double unit = double.Parse(Math.Pow(10, lenOfInt - 1 - i).ToString());

string strUnit = integerUnitToChineseUpper(unit);

//数值

string strValue = numToChineseUpper(moneyInt[i]);

builerInt.Append(strValue + strUnit);

}

builerInt.Append("整");

}

//小数部份

StringBuilder builerDecimal = new StringBuilder();

if (arraryMoney.Length == 2)
{

builerInt.Remove(builerInt.Length - 1, 1); //移除 "整"

string moneyDecimal = arraryMoney[1];

int lenOfDecimal = moneyDecimal.Length;

for (int i = 0; i < lenOfDecimal; i++)
{

double unit = double.Parse(Math.Pow(10, i).ToString());

string strUnit = decimalUnitToChineseUpper(unit);

//数值

string strValue = numToChineseUpper(moneyDecimal[i]);

builerDecimal.Append(strValue + strUnit);

}

}

return builerInt.ToString() + builerDecimal.ToString();

}

/// <summary>

/// 将阿拉伯数字转换为大写汉字

/// </summary>

/// <param name="num"></param>

/// <returns></returns>

private static string numToChineseUpper(char charnum)
{

string strValue = string.Empty;

switch (charnum)
{

case '1': strValue = "壹"; break;

case '2': strValue = "貳"; break;

case '3': strValue = "叁"; break;

case '4': strValue = "肆"; break;

case '5': strValue = "伍"; break;

case '6': strValue = "陸"; break;

case '7': strValue = "柒"; break;

case '8': strValue = "捌"; break;

case '9': strValue = "玖"; break;

case '0': strValue = "零"; break;

}

return strValue;

}


/// <summary>

/// 将金额的整数部份转换为汉字单位

/// </summary>

/// <param name="unit"></param>

/// <returns></returns>

private static string integerUnitToChineseUpper(double unit)
{

string strUnit = string.Empty;

if (unit == 1)

strUnit = "元";

else if (unit == 10)

strUnit = "拾";

else if (unit == 100)

strUnit = "佰";

else if (unit == 1000)

strUnit = "仟";

else if (unit == 10000)

strUnit = "萬";

else if (unit == 100000)

strUnit = "拾";

else if (unit == 1000000)

strUnit = "佰";

else if (unit == 10000000)

strUnit = "仟";

else if (unit == 100000000)

strUnit = "亿";

else if (unit == 1000000000)

strUnit = "拾";

else if (unit == 10000000000)

strUnit = "佰";

else if (unit == 100000000000)

strUnit = "仟";

else

strUnit = "萬";

return strUnit;

}

/// <summary>

/// 将金额的小数部份单位转换为汉字单位

/// </summary>

/// <param name="unit"></param>

/// <returns></returns>

private static string decimalUnitToChineseUpper(double unit)
{

string strUnit = string.Empty;

if (unit == 1)

strUnit = "角";

else if (unit == 10)

strUnit = "分";

else if (unit == 100)

strUnit = "厘";

else if (unit == 1000)

strUnit = "毫厘";

else if (unit == 10000)

strUnit = "微厘";

else

strUnit = "?";

return strUnit;

}

}

原文地址:https://www.cnblogs.com/lucoo/p/3056597.html