C#:小寫金額轉換為大寫

來源:互聯網
上載者:User

標籤:blog   io   os   ar   for   div   art   sp   log   

        #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    

 

C#:小寫金額轉換為大寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.