Home >Web Front-end >JS Tutorial >How to convert the amount from lowercase to uppercase in js

How to convert the amount from lowercase to uppercase in js

小云云
小云云Original
2018-03-19 17:56:163212browse

本文主要和大家分享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, "元整");

    }

相关推荐:

php怎么将字符串的首字母转换成大写的方法

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn