/**
* 处理价格,默认是元,分第二个参数传100
* dealPrice(5) => 5.00;dealPrice(500, 100) => 5.00;
*/
export function dealPrice(x, d = 0) {
let f = parseFloat(x);
if (isNaN(f)) {
return;
}
if (f == 0) {
return f;
}
d = d ? d * 100 : 100;
f = Math.round(f * 100) / d;
let s = f.toString();
let rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
js,底层处理price处理方法
最新推荐文章于 2023-04-12 18:02:42 发布