商务合作:179001057@qq.com

数字金额转为大写金额(C#)

技术2022-05-11  0


某平台价值19860元的编程课程资料免费领取【点我领取】


    /// <summary>金额转大写    ///     /// </summary>    public class MoneyConvertChinese    {        /// <summary>金额转大写        ///         /// </summary>        /// <param name="LowerMoney"></param>        /// <returns></returns>        public string MoneyToChinese(string LowerMoney)        {            string functionReturnValue = null;            bool IsNegative = false// 是否是负数            if (LowerMoney.Trim().Substring(01== "-")            {                // 是负数则先转为正数                LowerMoney = LowerMoney.Trim().Remove(01);                IsNegative = true;            }            string strLower = null;            string strUpart = null;            string strUpper = null;            int iTemp = 0;            // 保留两位小数 123.489→123.49  123.4→123.4            LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();            if (LowerMoney.IndexOf("."> 0)            {                if (LowerMoney.IndexOf("."== LowerMoney.Length - 2)                {                    LowerMoney = LowerMoney + "0";                }            }            else            {                LowerMoney = LowerMoney + ".00";            }            strLower = LowerMoney;            iTemp = 1;            strUpper = "";            while (iTemp <= strLower.Length)            {                switch (strLower.Substring(strLower.Length - iTemp, 1))                {                    case ".":                        strUpart = "";                        break;                    case "0":                        strUpart = "";                        break;                    case "1":                        strUpart = "";                        break;                    case "2":                        strUpart = "";                        break;                    case "3":                        strUpart = "";                        break;                    case "4":                        strUpart = "";                        break;                    case "5":                        strUpart = "";                        break;                    case "6":                        strUpart = "";                        break;                    case "7":                        strUpart = "";                        break;                    case "8":                        strUpart = "";                        break;                    case "9":                        strUpart = "";                        break;                }                switch (iTemp)                {                    case 1:                        strUpart = strUpart + "";                        break;                    case 2:                        strUpart = strUpart + "";                        break;                    case 3:                        strUpart = strUpart + "";                        break;                    case 4:                        strUpart = strUpart + "";                        break;                    case 5:                        strUpart = strUpart + "";                        break;                    case 6:                        strUpart = strUpart + "";                        break;                    case 7:                        strUpart = strUpart + "";                        break;                    case 8:                        strUpart = strUpart + "";                        break;                    case 9:                        strUpart = strUpart + "";                        break;                    case 10:                        strUpart = strUpart + "";                        break;                    case 11:                        strUpart = strUpart + "";                        break;                    case 12:                        strUpart = strUpart + "亿";                        break;                    case 13:                        strUpart = strUpart + "";                        break;                    case 14:                        strUpart = strUpart + "";                        break;                    case 15:                        strUpart = strUpart + "";                        break;                    case 16:                        strUpart = strUpart + "";                        break;                    default:                        strUpart = strUpart + "";                        break;                }                strUpper = strUpart + strUpper;                iTemp = iTemp + 1;            }            strUpper = strUpper.Replace("零拾""");            strUpper = strUpper.Replace("零佰""");            strUpper = strUpper.Replace("零仟""");            strUpper = strUpper.Replace("零零零""");            strUpper = strUpper.Replace("零零""");            strUpper = strUpper.Replace("零角零分""");            strUpper = strUpper.Replace("零分""");            strUpper = strUpper.Replace("零角""");            strUpper = strUpper.Replace("零亿零万零圆""亿圆");            strUpper = strUpper.Replace("亿零万零圆""亿圆");            strUpper = strUpper.Replace("零亿零万""亿");            strUpper = strUpper.Replace("零万零圆""万圆");            strUpper = strUpper.Replace("零亿""亿");            strUpper = strUpper.Replace("零万""");            strUpper = strUpper.Replace("零圆""");            strUpper = strUpper.Replace("零零""");            // 对壹圆以下的金额的处理            if (strUpper.Substring(01== "")            {                strUpper = strUpper.Substring(1, strUpper.Length - 1);            }            if (strUpper.Substring(01== "")            {                strUpper = strUpper.Substring(1, strUpper.Length - 1);            }            if (strUpper.Substring(01== "")            {                strUpper = strUpper.Substring(1, strUpper.Length - 1);            }            if (strUpper.Substring(01== "")            {                strUpper = strUpper.Substring(1, strUpper.Length - 1);            }            if (strUpper.Substring(01== "")            {                strUpper = "零圆整";            }            functionReturnValue = strUpper;            if (IsNegative == true)            {                return "" + functionReturnValue;            }            else            {                return functionReturnValue;            }        }    }

 

测试代码:

         static   void  Main( string [] args)        {            Console.Write( " 请输入要转成大写的数字: " );             string  str  =  Console.ReadLine();            Console.WriteLine( " 大写: "   +   new  MoneyConvertChinese().MoneyToChinese(str));            Console.ReadLine();        } 文章来源:http://www.cnblogs.com/niunan/archive/2009/07/06/1517992.html

最新回复(0)