angularjs过滤器金额大写
html:
使用过虑器:
<li>
<i>
<img src="images/red_star.png" alt="必填项">
<span>金额大写:</span>
</i>
<em>
<span class="fl" v-show="Amount">{{Amount|amountFtr}}</span>
</em>
</li>
js:
function amount() {
return function (input) {
if (input !== undefined) {
if(parseFloat(input)==parseFloat(0)){
return "零元整";
}
var strOutput = "", strUnit = '仟佰拾兆仟佰拾亿仟佰拾万仟佰拾元角分';
input += "00";
var intPos = input.indexOf('.');
if (intPos >= 0) {
input = input.substring(0, intPos) + input.substr(intPos + 1, 2);
}
strUnit = strUnit.substr(strUnit.length - input.length);
for (var i = 0; i < input.length; i++) {
strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(input.substr(i, 1), 1) + strUnit.substr(i, 1);
}
return strOutput.replace(/^零角零分$/, '').replace(/零角零分$/, '整').replace(/^零元零角/, '').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([兆|亿|万])/g, '$1').replace(/零+元/, '元').replace(/兆零{0,3}亿/, '兆').replace(/亿零{0,3}万/, '亿').replace(/兆零{0,3}万/, '兆').replace(/^元/, "零元").replace(/零角/, '零').replace(/零元/, '').replace(/零分$/, "");
}
return input;
};
}
vx.module('ibsapp.libraries').filter('amountFtr', amount);
})(window, window.vx);