1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Vue.filter('amount', function (input) { if (input !== undefined) { const intPosTwo = input.indexOf(','); if (intPosTwo) { input = input.replace(/,/g, ''); } if (parseFloat(input) < 0 || isNaN(input) || input === '') { return '零元整'; } input = String(parseFloat(input)); let strOutput = ''; let strUnit = '仟佰拾万仟佰拾亿仟佰拾万仟佰拾元角分'; input += '00'; const intPos = input.indexOf('.'); if (intPos >= 0) { input = input.substring(0, intPos) + input.substr(intPos + 1, 2); } strUnit = strUnit.substr(strUnit.length - input.length); for (let i = 0; i < input.length; i++) { strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(input.substr(i, 1), 1) + strUnit.substr(i, 1); } strOutput = strOutput .replace(/零角零分$/, '整') .replace(/零[仟佰拾]/g, '零') .replace(/零{2,}/g, '零') .replace(/零([亿|万])/g, '$1') .replace(/零+元/, '元') .replace(/亿零{0,3}万/, '亿') .replace(/^元/, '零元') .replace(/零角/, '零') .replace(/零分/, ''); if (parseFloat(input) === 0) { return '零元整'; } if (parseFloat(input) > 0 && parseFloat(input) < 100) { return strOutput.replace(/零元/, '').replace(/零/, ''); } return strOutput; } return '零元'; });
|