toFixed有时候是四舍五入,有时候不是,查了下资料,说是银行家舍入法
然后就需要自己写
myFixed(val, num) {
val= parseFloat(val);
return (Math.round((val+ Number.EPSILON) * Math.pow(10, num)) / Math.pow(10, num)).toFixed(num);
}
使用Number计算精度问题,然后再使用toFiexd方法
toFixed有时候是四舍五入,有时候不是,查了下资料,说是银行家舍入法
然后就需要自己写
myFixed(val, num) {
val= parseFloat(val);
return (Math.round((val+ Number.EPSILON) * Math.pow(10, num)) / Math.pow(10, num)).toFixed(num);
}
使用Number计算精度问题,然后再使用toFiexd方法