比如0.00241234 * 100=0.24123399999999998
这里的结果需要有多少展示多少
function floatNum(f, d, n) {
let m = Math.pow(10, d);
let num = (Math.round(f * m) * n) / m;
return num;
}
//f小数,d是需要乘以10的多少次方(小数点有几位),n要乘的整数
bb=0.00241234
//获取小数点后有几位
let aa=bb.toString().split('.')[1].length
//aa 8
floatNum(0.00241234, 8, 100) //0.241234
亲试有用
function float(f, d) {
let m = Math.pow(10, d);
let num = Math.round(f * m) / m;
return num;
float(0.1 + 0.2, 1); //0.3
//解决0.1+0.2不等于0.3