leafiy
5/18/2018 - 6:53 PM

四舍五入到指定位数 #js #number

round

const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
// round(1.005, 2) -> 1.01