四舍五入 const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed); const toPrecision = (number, c) => (Math.round(+number * 10 ** c) / 10 ** c).toFixed(c);
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed);
const toPrecision = (number, c) => (Math.round(+number * 10 ** c) / 10 ** c).toFixed(c);
浮点数
保留小数位
round(1.2345, 2); /// 1.23round(0.355, 2); /// 0.36round(1.005, 2); /// 1.01 Copy
round(1.2345, 2); /// 1.23round(0.355, 2); /// 0.36round(1.005, 2); /// 1.01
四舍五入
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed);
const toPrecision = (number, c) => (Math.round(+number * 10 ** c) / 10 ** c).toFixed(c);