c# 阿拉伯數字轉成中文

來源:互聯網
上載者:User

標籤:div   sys   equal   ons   pow   using   ext   http   ace   

調用方法: public string ConvertToChineseNumber(string old)        {            Chinese ch = new Chinese();            long num = Convert.ToInt64(old);            string re = ch.returnResult(num);            if (re.StartsWith("壹拾"))            {                re = re.Substring(1, re.Length - 1);            }            return (re);        }

 

完整代碼using System;using System.Collections.Generic;using System.Text;namespace Public{    class Chinese    {        public string returnResult(long num)        {            string numStr = num.ToString();            if (numStr.Length > 8 & numStr.Length < 16)            {                string[] firstSplit = new string[2];                firstSplit[0] = numStr.Substring(0, numStr.Length - 8);                firstSplit[1] = numStr.Substring(numStr.Length - 8, 8);                string result1 = getString(firstSplit[0]) + "億";                string result2 = getString(firstSplit[1]);                return result1 + result2;            }            else            {                return getString(numStr);            }        }        public string getString(string str)        {            if (str.Length > 4)            {                string[] secondSplit = new string[2];                secondSplit[0] = str.Substring(0, str.Length - 4);                secondSplit[1] = str.Substring(str.Length - 4, 4);                string result1 = getRe(secondSplit[0]);                string result2 = getRe(secondSplit[1]);                if (!secondSplit[0].Equals("0000"))                {                    result1 += "萬";                }                return result1 + result2;            }            else            {                return getRe(str);            }        }        int[] value = { 1000, 100, 10 };        public string getRe(string doWith)        {            char[] number = doWith.ToCharArray();            int length = number.Length;            string re = "";            for (int i = 0; i < length; i++)            {                switch (number[i])                {                    case ‘0‘:                        if (re.EndsWith("零"))                        {                            re += "";                        }                        else                        {                            re += "零";                        }                        break;                    case ‘1‘:                        re += "壹";                        break;                    case ‘2‘:                        re += "貳";                        break;                    case ‘3‘:                        re += "三";                        break;                    case ‘4‘:                        re += "肆";                        break;                    case ‘5‘:                        re += "伍";                        break;                    case ‘6‘:                        re += "陸";                        break;                    case ‘7‘:                        re += "柒";                        break;                    case ‘8‘:                        re += "捌";                        break;                    case ‘9‘:                        re += "玖";                        break;                }                int index = (int)Math.Pow(10, length - i - 1);                if (number[i].ToString() == "0")                {                    index = -1;                }                switch (index)                {                    case 1000:                        re += "仟";                        break;                    case 100:                        re += "佰";                        break;                    case 10:                        re += "拾";                        break;                }            }            if (re.EndsWith("零"))            {                re = re.Substring(0, re.Length - 1);            }            return re;        }    }}

 

 

http://files.cnblogs.com/files/louby/1279894919.rar

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.