重庆熊猫 Loading

JavaScript 四舍五入到指定位数

const round = (n, d) => Number(`${Math.round(`${n}e${d}`)}e-${d}`);

let result1 = round(1.666, 2)
let result2 = round(1.888, 2)
console.log(result1);
console.log(result2);
posted @ 2022-10-24 09:00  重庆熊猫  阅读(17)  评论(0编辑  收藏  举报