Home >Web Front-end >JS Tutorial >How to convert the amount from lowercase to uppercase in js
本文主要和大家分享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++) return str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整"); }
相关推荐:
The above is the detailed content of How to convert the amount from lowercase to uppercase in js. For more information, please follow other related articles on the PHP Chinese website!