例如我有以下数字:
30、270、530、1110
但我希望每个都四舍五入为:
40、280、540、1120
这可能吗?
只需除以 20,四舍五入并乘以 20:
const nums = [30, 273, 530, 1110]; nums.forEach(num => { const rounded = Math.round(num / 20) * 20; console.log(rounded); });