/** * money formatter, will add <small> tag for the yuan and the decimal * <div ng-bind-html="number|slMoney [:shrink [:noHtml :decimalLength]]"></div> * */ sl.filter('slMoney',['$filter','$sce',function($filter,$sce) { /** * @number input number , by default (mostly used) : 32123.34 --> 32,123<small>.34元</small> * @shrink true -- will put wy at the end , * should use this only when the number is multiple of 100, * or with decimal 2 will lose the money in position 1 and 2 * slMoney(11230,true)--> 1<small>.12万元</small> , 30 will lost * @noHtml true -- won't add the <small> tag * @decimalLength define the decimal length, default 2 , usually we use 2 * @noCurrencySign wont add yuan at the end */ return function(number,shrink,noHtml,decimalLength,noCurrencySign) { number = replaceMoneySign(number); var _nf = $filter('number'); var n = '', sign = y; var dl = decimalLength || decimalLength == 0 ? decimalLength : 2; if(!shrink) { n = _nf(number, dl); } else{ var multiple = 1,m=1e4; if(number >= m) { multiple = m; sign = wy; } n = _nf(number / multiple, number % multiple == 0 ? 0 : dl); } var index = n.indexOf('.'); var beforeDecimal = index < 0 ? n : n.substring(0, index); var afterDecimal = index < 0 ? '' : n.substring(index); sign = noCurrencySign ? '' : sign; var res = beforeDecimal + (!noHtml ? '<small>':'') + afterDecimal + sign + (!noHtml ? '</small>':''); return $sce.trustAsHtml(res); }; }]);
// js使用 sl.directive('slPlanCard', ['$sce', '$filter', function($sce, $filter){ amountObj.innerHTML = $filter('slMoney')(amount, true, true); }
<!-- html使用 -->
<p>{{ plan.minInvestAmount | slMoney:true:true }}</p>