转换为大写金额
var DM = { /** * 金额大写转换函数 */ cnyNumber4CN: function(n) { n = DM.unfmtAmt(n); if("" == n){ return ""; } 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); } str = str.replace(/零(仟|佰|拾|角)/g, "零") .replace(/(零)+/g, "零") .replace(/零(万)/g, "万零") .replace(/零(亿)/g, "亿零") .replace(/零(元)/g, "元零") .replace(/(零)+/g, "零") .replace(/^元零?|零分/g, "") .replace(/零元/g, "元") .replace(/零(万|亿)/g, "") .replace(/亿万/g, "亿") .replace(/元$/g, "元整 "); if (str == "分") { str = "零元整"; } return str; }, /** * 金额去格式化 */ unfmtAmt: function(s){ return s.replace(/,/g,"").replace(/(^\s*)|(\s*$)/g, ""); } };
调用实例: cap:function(){ var capital=$("#TRAN_AMT").val(); var ca=DM.cnyNumber4CN(capital); $("#capital").val(ca); }, capital").val(ca); ========================= <li> <div class="colL"> <label>转账金额:</label> </div> <div class="col"> <input type="text" id="TRAN_AMT" onblur="App.cap()"> </div> </li> <li> <div class="colL"> <label>大写金额:</label> </div> <div class="col"> <span id="capital"></span> </div> </li>