formatNumber = (cur, digit) => {
let temp = cur.toFixed(digit);
let i = 1;
while (temp.charAt(temp.length - 1) === ‘0’ && i <= digit) {
if (i === digit) {
temp = temp.substring(0, temp.length - 2);
} else {
temp = temp.substring(0, temp.length - 1);
}
i++;
}
return isNaN(temp) ? 0 : temp;
};
JavaScript 保留n位小数去尾0
最新推荐文章于 2022-09-16 19:23:31 发布