zoukankan      html  css  js  c++  java
  • 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
    
        
    
  • 相关阅读:
    ReactiveX-简介
    docker简记
    ethereum-在Ubuntu上搭建私有链
    netflix-ribbon简介
    netflix-hystrix-简例
    netflix-hystrix-原理[译]
    netflix-hystrix-简介[译]
    JS简记-委托
    JS简记-对象关联
    JS简记-原型二
  • 原文地址:https://www.cnblogs.com/shenchao/p/3981603.html
Copyright © 2011-2022 走看看