zoukankan      html  css  js  c++  java
  • JS 数字转换为大写金额

      function DX(n) {
     
             if (!/^(0|[1-9]d*)(.d+)?$/.test(n))
                 return "数据非法";
             var unit = "千百拾亿千百拾万千百拾元角分", str = "";
                 n += "00";
             var p = n.indexOf('.');
             if (p >= 0)
                 n = n.substring(0, p) + n.substr(p+1, 2);
                 unit = unit.substr(unit.length - n.length);
             for (var i=0; i < n.length; i++)
                 str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
             return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
     }

      

    function format (num) {
            return (num.toFixed(2) + '').replace(/d{1,3}(?=(d{3})+(.d*)?$)/g, '$&,');
        }
    

      

    
    
    function rmoney(s) 
    { 
    return parseFloat(s.replace(/[^d.-]/g, "")); 
    } 
    

      



  • 相关阅读:
    many2many
    oneselfone
    one2one
    10-many2one
    08-one2many
    05-curd
    动态SQl
    文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
    expect用法举例
    通过命令修改mysql的提示符
  • 原文地址:https://www.cnblogs.com/xhtml5/p/5735363.html
Copyright © 2011-2022 走看看