// 保留两位小数
Vue.filter('dTofixed', function(value) {
var isNum = parseFloat(value);
if (!isNum) {
return "0.00";
} else {
var value = Math.round(isNum * 100) / 100;
var item = value.toString().split(".");
if (item.length == 1) {
value = value.toString() + ".00";
return value;
}
if (item.length > 1) {
if (item[1].length < 2) {
value = value.toString() + "0";
}
return value;
}
}
})
// 数字前面加¥
Vue.filter('dCurrency', function(value) {
if (!value) {
return ''
} else {
return '¥' + value
}
})
调用方式
<span>{{0.4 | dTofixed | dCurrency}}</span>
显示结果 ¥0.40