参考:
1. JavaScript 浮点数陷阱及解法 https://www.cnblogs.com/sunshq/p/7682109.html
封装成方法就是:
function strip(num, precision = 12) {
return +parseFloat(num.toPrecision(precision));
}
2. JavaScript 浮点数运算的精度问题 https://www.html.cn/archives/7340
function strip(num, precision = 12) {
return +parseFloat(num.toFixed(precision));
}