zoukankan      html  css  js  c++  java
  • 金额小写转换为大写脚本

    1.脚本

    <script type="text/jscript">
        $(function () {
            $("#<%=txtFundingEstimatesUpper.ClientID %>").val(ConvertMoney($("#<%=txtFundingEstimates.ClientID %>").val()));
            //金额变化时转为大写    
            $("#<%=txtFundingEstimates.ClientID %>").bind("input propertychange", function () {
                var upperMoney = ConvertMoney($(this).val());
                $("#<%=txtFundingEstimatesUpper.ClientID %>").val(upperMoney);
            });
        });
    
        function ConvertMoney(strg) {
            strg = strg.replace(/,/g, "");
            var number = Math.round(strg * 100) / 100;
            number = number.toString(10).split(".");
            var a = number[0];
            if (a.length > 12)
                return "数值超出范围!";
            var e = "零壹贰叁肆伍陆柒捌玖";
            var num1 = "";
            var len = a.length - 1;
            for (var i = 0; i <= len; i++)
                num1 += e.charAt(parseInt(a.charAt(i))) + [["", "", "亿"][Math.floor((len - i) / 4)], "", "", ""][(len - i) % 4];
            if (number.length == 2 && number[1] != "") {
                var a = number[1]; for (var i = 0; i < a.length; i++)
                    num1 += e.charAt(parseInt(a.charAt(i))) + ["", ""][i];
            }
            num1 = num1.replace(/零佰|零拾|零仟|零角/g, "");
            num1 = num1.replace(/零{2,}/g, "");
            num1 = num1.replace(/零(?=圆|万|亿)/g, "");
            num1 = num1.replace(/亿万/, "亿");
            num1 = num1.replace(/^圆零?/, "");
            if (num1 != "" && !/分$/.test(num1))
                num1 += "";
            return num1;
        }
    </script>
    View Code


    2.页面控件

    <table>
    <tr>
            <td class="EditBox_TD" width="15%">经费概算<font class="red">*</font></td>
            <td class="EditBox_TD1" width="35%">
                <asp:TextBox ID="txtFundingEstimates" runat="server" Width="80%" data-options="required:true,validType:'money'"></asp:TextBox>元</td>
            <td class="EditBox_TD" width="15%">大写</td>
            <td class="EditBox_TD1" width="35%">
                <asp:TextBox ID="txtFundingEstimatesUpper" runat="server" Width="80%" ReadOnly="true"></asp:TextBox>
            </td>
        </tr>
    </table>
    View Code

    3.显示效果

  • 相关阅读:
    HDU 1421 DP
    HDU1011 树形DP
    CodeForces 219D 树形DP
    HDU2196 树形DP
    HDU5831
    HDU3177 贪心
    数位DP HDU3652
    数位DP bzoj1026
    数位DP HDU3555
    数位DP HDU2089
  • 原文地址:https://www.cnblogs.com/ywblog/p/3435887.html
Copyright © 2011-2022 走看看