• 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
    
        
    
  • 相关阅读:
    解决ecshop进入后台服务器出现500的问题
    Java8新特性(拉姆达表达式lambda)
    使用Optional优雅处理null
    Arrays.asList 存在的坑
    Java提供的几种线程池
    冒泡排序及优化详解
    如何让MySQL语句执行加速?
    关于https的五大误区
    127.0.0.1和0.0.0.0地址的区别
    宽带网络技术-大题重点
  • 原文地址:https://www.cnblogs.com/shenchao/p/3981603.html
Copyright © 2020-2023  润新知