将数字金额转化为汉字大写

1 篇文章 0 订阅

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace MoneyToChineseUpper

{

    /// <summary>

    /// 将数字金额转换为大写汉字金额

    /// </summary>

    public class Converter

    {

        public static string Convert(doublemoney)

        {

            string strMoney = money.ToString();

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

 

            //整数部分

            StringBuilder builerInt = newStringBuilder();

            if (arraryMoney != null)

            {

                stringmoneyInt = arraryMoney[0];

                int lenOfInt = moneyInt.Length;

                int zeroNum = 0;

                for (int i = 0; i< lenOfInt; i++)

                {

 

 

                       

                    //单位

                    doubleunit = 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++)

                {

                    doubleunit = 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(charnum)

        {

            string strValue = string.Empty;

            switch (num)

            {

                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= "仟";

            elseif (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;

        }

 

    }

}

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值