function toCapital(num) { var strOutput = ""; var strUnit = ‘仟佰拾亿仟佰拾万仟佰拾元角分‘; num += "00"; //小数点位置 var intPos = num.indexOf(‘.‘); //大于0,就是有小数 if (intPos >= 0) { //截取小数点后两位. num = num.substring(0, intPos) + num.substr(intPos + 1, 2); } //获取与num相应的strUnit strUnit = strUnit.substr(strUnit.length - num.length); for (var i = 0; i < num.length; 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(/^元/, "零元"); }
时间: 2024-10-01 20:27:44