从tenpay找到的一段将金额小写转换成大写的js代码:
1 var DX = function (num) { 2 var strOutput = ""; 3 var strUnit = ‘仟佰拾亿仟佰拾万仟佰拾元角分‘; 4 num += "00"; 5 var intPos = num.indexOf(‘.‘); 6 if (intPos >= 0) 7 num = num.substring(0, intPos) + num.substr(intPos + 1, 2); 8 strUnit = strUnit.substr(strUnit.length - num.length); 9 for (var i=0; i < num.length; i++) 10 strOutput += ‘零壹贰叁肆伍陆柒捌玖‘.substr(num.substr(i,1),1) + strUnit.substr(i,1); 11 return strOutput.replace(/零角零分$/, ‘整‘).replace(/零[仟佰拾]/g, ‘零‘).replace(/零{2,}/g, ‘零‘).replace(/零([亿|万])/g, ‘$1‘).replace(/零+元/, ‘元‘).replace(/亿零{0,3}万/, ‘亿‘).replace(/^元/, "零元"); 12 };
时间: 2024-10-13 05:56:10