• 数字金额转成中文大字


    /// <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;

    }

    }

  • 相关阅读:
    VS2005 web程序自定义安装包的制作[转]
    "控件必须放在具有 runat=server 的窗体标记内"错误的解决方法
    Reader转化为Entity类时系统性能的测试报告
    NetBeans6.1(6.5)Visual Web JSF 应用程序开发的一个BUG
    .net操作PDF的一些资源(downmoon收集)
    NetBeans中jsp或java乱码的几种办法(downmoon收集)
    后微软时代,我们还能依靠谁?(downmoon原创)
    从dataReader到Entity转化时利用Reflect示例(解决OutOfRangeException错误)(downmoon)
    HttpCookie.HttpOnly VS Cookie.HttpOnly?(downmoon原创)
    Windows PowerShell 编写正则表达式(转自TechNet Magazine)
  • 原文地址:https://www.cnblogs.com/lucoo/p/3056597.html
Copyright © 2020-2023  润新知