1、转成千分位,保留两位
comdify(n) {
let num = Number(n);
let re = /\d{1,3}(?=(\d{3})+$)/g;
let n1 = num.toFixed(2).replace(/^(\d+)((\.\d+)?)$/, function (s, s1, s2) {
return s1.replace(re, "$&,") + s2;
});
return n1;
},
2、去除千分位
delcommafy(num){//去除千分位中的‘,’
if(num&&num!='undefined'&&num!='null'){
let numS = num;
numS = numS.toString();
numS = numS.replace(/,/gi, '');
return numS;
}else {
return num;
}
},