最近可爱的产品提了点要求,金额尾部需要.00 而且还要带千位符。
html: <el-input v-model="form.projectAmount" type="txet" placeholder="请输入项目金额"
@blur="projectAmounts" clearable :maxlength="32"></el-input> js:
toThousandsNoZero(num) { return num ? (
(isNaN(parseFloat(num.toString().replace(/,/g, ""))) ? 1 :
parseFloat(num.toString().replace(/,/g,
"")))).toFixed(2).toString().replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
return $1 + ","; }) : ""; }, projectAmounts(){//this.form.projectAmount 金额
if(isNaN(parseFloat(this.form.projectAmount))){ this.form.projectAmount= 0.00;
}else{ this.form.projectAmount=this.toThousandsNoZero(this.form.projectAmount);
} },
效果: