C#:小写金额转换为大写

        #region 小写金额转换为大写
        public static string CurrToChnNum(double Currnum)
        {
            string sResult = "";
            if (Math.Abs(Currnum) < 1e-20)
                return "零圆整";
            if (Currnum < 1e-20)
                sResult = "负";
            sResult = sResult + StringToChnNum(Math.Abs(Math.Round(Currnum, 2)).ToString());
            return sResult;
        }
        private static string FourNumToChnNum(string Str, string ChnNum, ref Boolean Pre)
        {
            string[] Digits = {"零", "壹", "贰", "叁", "肆",
                                     "伍", "陆", "柒", "捌", "玖"};
            int i, j, Len;
            string sResult = "";
            Len = Str.Length;
            for (i = 0; i < Len; i++)
            {
                j = Str[i] - 48;
                if (0 == j)
                    Pre = true;
                else
                {
                    if (Pre) sResult = sResult + "零";
                    sResult = sResult + Digits[j] + ChnNum.Substring(Len - i - 1, 1);
                    Pre = false;
                }
            }
            return sResult.Trim();
        }
        //将格式化好的小写串转换为大写串
        private static string StringToChnNum(string str)
        {
            const string ChnNum1 = "圆万亿兆";
            int i, Len, Len1, Level, Start;
            string s1; string s;
            Boolean Pre;
            string sResult = "";
            Len = str.IndexOf('.');
            Level = (Len + 3) / 4;
            Len1 = Len % 4;
            if (0 == Len1) Len1 = 4;
            Start = 0;
            for (i = 1; i <= Level; i++)
            {
                Pre = false;
                s = str.Substring(Start, Len1);
                s1 = FourNumToChnNum(s, " 拾佰仟", ref Pre);
                if (s1.Length > 0)
                    sResult = sResult + s1 + ChnNum1.Substring(Level - i, 1);
                Start = Start + Len1;
                Len1 = 4;
            }
            Pre = false;
            s1 = FourNumToChnNum(str.Substring(Len + 1, Math.Min(2, str.Length - Len - 1)), "分角", ref Pre);
            //s1 = "";
            if (s1.Length == 0)
                s1 = "整";
            sResult = sResult + s1;
            return sResult;
        }
        #endregion

    

 

转载于:https://www.cnblogs.com/shenchao/p/3981603.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值