我需要将浮点值四舍五入为最接近的整数,例如 value 是2.4 = 2如果我的价值是2.5 = 3我使用 round()、floor() 和 toFixed() 但它只做了向上、向下、相等的数字。
1 回答

慕少森
TA贡献2019条经验 获得超9个赞
你只需要 JavaScript 的 Math.round 方法:
console.log(Math.round(2.4));
console.log(Math.round(2.5));
添加回答
举报
0/150
提交
取消