js改为cs 小写金额转换为大写金额

public static string NumGetStr(string num)
        {
            try
            {
                char[] Ls_Shz = new char[] { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '扒', '玖' };
                string[] Ls_DW_sh = new string[] { "万亿", "拾佰仟", "分角" };
                if (string.IsNullOrEmpty(num))
                    return "";
                Regex reg = new Regex(@"/^(([1-9](\d)*)|0)(\.(\d){1,2})?$/g");
                string[] strNum = null;
                int numLen = 0;
                if (num.Contains("."))
                {
                    strNum = num.Split('.');
                }
                numLen = strNum[0].Length;
                string strRtn = string.Empty;
                string unit = string.Empty;
                for (int a = numLen; a > 0; a--)
                {
                    int intNum_ZS = int.Parse(strNum[0].Substring(numLen - a, 1));
                    if (a % 4 == 1)
                    {
                        unit = (a - 1) / 4 == 0 ? "" : Ls_DW_sh[0].Substring((1 - ((a - 1) / 4) % 2), 1);
                        if (intNum_ZS != 0)
                        {
                            strRtn += Ls_Shz[intNum_ZS] + unit;
                        }
                        else if (strRtn != "")
                        {
                            if (strRtn.Substring((strRtn.Length - 1),1) == "零")
                            {
                                strRtn = strRtn.Substring(0, (strRtn.Length - 1));
                                strRtn += unit;
                            }
                        }
                    }
                    else
                    {
                        if (intNum_ZS == 0)
                        {
                            if (strRtn != "" &&  strRtn.Substring((strRtn.Length - 1),1) != "零")
                                strRtn += "零";
                        }
                        else if (intNum_ZS == 1 && (a - 2) % 4 == 0)
                        {
                            unit = Ls_DW_sh[1].Substring((a - 2) % 4, 1);
                            strRtn += unit;
                        }
                        else
                        {
                            unit = Ls_DW_sh[1].Substring((a - 2) % 4, 1);
                            strRtn += Ls_Shz[intNum_ZS] + unit;
                        }
                    }
                }
                if (strNum.Length == 2)
                {
                    string pointNums = strNum[1].Length < 3 ? strNum[1] : strNum[1].Substring(0, 2);
                    if (int.Parse(pointNums) == 00)
                    {
                        strRtn += strRtn != "" ? "圆整" : "";
                    }
                    else
                    {
                        if (strRtn != null)
                            strRtn += "圆";
                        for (int b = 0; b < pointNums.Length; b++)
                        {
                            var d = int.Parse(pointNums.Substring(b, 1));
                            if (d == 0)
                            {
                                if (b == 0 && strRtn != "")
                                    strRtn += "零";
                            }
                            else
                            {
                                strRtn += Ls_Shz[d] + Ls_DW_sh[2].Substring((1 - b), 1);
                            }
                        }
                    }
                    if (strRtn == "")
                        strRtn = "零圆整";
                }
                else
                {
                    strRtn += strRtn == "" ? "零圆整" : "圆整";
                }
                return strRtn;
            }
            catch (Exception ex)
            {
                throw new Exception("转换为大写金额出错", ex);
            }
        }

转载于:https://www.cnblogs.com/changweiLi/p/3498020.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值