数字转为大写金额(C#)

数字转为大写(C#)

        /// <summary>
        /// 数字转为中文()
        /// </summary>
        /// <param name="strNum">数字字符串</param>
        /// <returns>转化后的中文字符串</returns>
        public static string NumToCN(string strNum)
        {
            //数字转换为中文后的数组
            string[] CN_num = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            //为数字位数建立一个位数组
            string[] CN_digit = new string[] { "", "拾", "佰", "仟" };
            //为数字单位建立一个单位数组
            string[] CN_units = new string[] { "", "万", "亿", "万" };

            string str_returnValue = "";    //返回值

            int finger = 0;     //字符位置指针
            int field_Length;   //字段长度
            int field_Num;      //字段数量

            if (strNum.Length % 4 == 0)
            { 
                field_Num = strNum.Length / 4;
                field_Length = 4;
            }
            else
            {  
                field_Num = strNum.Length / 4 + 1;
                field_Length = strNum.Length % 4;
            }

            for (int i = 0; i < field_Num; i++)
            { 
                string four = strNum.Substring(finger, field_Length);
                finger += field_Length;

                for (int j = 0; j < four.Length; j++)
                { 
                    if (four[j] != '0')
                    {
                        str_returnValue = str_returnValue + CN_num[Convert.ToInt32(four[j].ToString())];  
                        str_returnValue = str_returnValue + CN_digit[field_Length - 1];    
                    }
                    else
                    {   
                        if (j != four.Length - 1 && four[j + 1] != four[j])
                        {
                            str_returnValue = str_returnValue + CN_num[Convert.ToInt32(four[j].ToString())];
                        }
                    }

                    if (j != four.Length - 1)
                    {  
                        field_Length--;
                    }
                    else
                    {
                        if (Convert.ToInt32(four) != 0 || field_Num - 1 - i ==2)
                        {   
                            str_returnValue = str_returnValue + CN_units[field_Num - 1 - i];
                        }
                        field_Length = 4;
                    }
                }
            }
            return str_returnValue + "元";
        }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值