• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#小写转大写

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

#region 小写转大写
    private string GetNumToUpper(decimal Money)
    {        
        string NumList = "";  
        string RmbList = "";
        int NumLen = 0;  
        int NumChar = 0;
        string N1 = "";
        string N2 = "";
        decimal Mnu = 0;
        int I = 0;
        string numStr = "";
        string Change = "";

        Mnu = Money;
        if (Money > 0)
        {
            Money = Convert.ToDecimal(Money.ToString("#.00"));
        }
        else
        {
            Money = Convert.ToDecimal(Money.ToString("#.00")) * -1;
        }

        NumList = "零壹贰叁肆伍陆柒捌玖";
        RmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万";

        if (Money > 9999999999999.99M)
        {
            return   "-------";     //超出范围的人民币值,无法显示!;
        }

        numStr = Convert.ToString(Convert.ToDecimal(Money * 100).ToString("#"));
        NumLen = numStr.Length;

        I = 0;
        while (I <= NumLen -1)
        {
            NumChar = Convert.ToInt32(numStr.Substring(I, 1));
            N1 = NumList.Substring(NumChar, 1);
            N2 = RmbList.Substring(NumLen - I -1, 1);

            if (N1 != "零")
            {
                Change += N1 + N2;
            }
            else
            {
                    if (N2 == "亿" || N2 == "万" || N2 == "元" || N1 == "零")
                    {
                        while (Change.Substring(Change.Length - 1, 1) == "零")
                        {
                             Change = Change.Substring(0, Change.Length - 1);
                        }
                    }
                    if (N2 == "亿" || (N2 == "万" && Change.Substring(Change.Length - 1, 1) != "亿") || N2 == "元")
                    {
                            Change   +=   N2;
                    }
                    else
                    {
                        if (Change.Substring(Change.Length - 2, 2).Substring(0, 1) == "零" || Change.Substring(Change.Length - 1, 1) != "亿")
                        {
                            Change   +=   N1;
                        }
                    }
            }
            I++;
        }
        if (Change.Length > 1)
        {
                while (Change.Substring(Change.Length - 1, 1) == "零")
                {
                    Change = Change.Substring(0, Change.Length - 1);
                }
                if (Change.Substring(Change.Length - 1, 1) == "元" || Change.Substring(Change.Length - 1, 1) == "角")
                {
                    Change += "整";
                }
        }

        if (Mnu > 0)
        {
            return Change;
        }
        else
        {
            if (Mnu < 0)
            {
                return "负" + Change;
            }
            else
            {
                return "零元整";
            }
        }
    }
    #endregion


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XceedFtp下载卡死解决方案发布时间:2022-07-13
下一篇:
C++——多维数组动态开辟与释放发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap