JS将数字转化为中文大写

2021-01-22 17:16

阅读:703

标签:chinese   length   substring   turn   ++   out   pre   span   ntp   

传入数字字符串即可

number_chinese(str) {
    var num = parseFloat(str);
    var strOutput = "",
        strUnit = ‘仟佰拾亿仟佰拾万仟佰拾元角分‘;
    num += "00";
    var intPos = num.indexOf(‘.‘);
    if (intPos >= 0) {
        num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
    }
    strUnit = strUnit.substr(strUnit.length - num.length);
    for (var i = 0; i ) {
        strOutput += ‘零壹贰叁肆伍陆柒捌玖‘.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);
    }
    return strOutput.replace(/零角零分$/, ‘整‘).replace(/零[仟佰拾]/g, ‘零‘).replace(/零{2,}/g, ‘零‘).replace(/零([亿|万])/g, ‘$1‘).replace(/零+元/, ‘元‘).replace(/亿零{0,3}万/, ‘亿‘).replace(/^元/, "零元")
},

 

JS将数字转化为中文大写

标签:chinese   length   substring   turn   ++   out   pre   span   ntp   

原文地址:https://www.cnblogs.com/hexuerui/p/13284854.html


评论


亲,登录后才可以留言!