toFixed(num,decimal) {
num = num.toString();
let index = num.indexOf('.');
if (index !== -1) {
num = num.substring(0, decimal + index + 1)
} else {
num = num.substring(0)
}
return parseFloat(num).toFixed(decimal)
}
let num = 12.129;
console.log(this.toFixed(num,2)) // ==> 12.12
JS保留指定小数位,不进行四舍五入
最新推荐文章于 2024-07-22 14:26:38 发布