可以使用 Math.floor() 函数将数字向下取整到最近的 10 的倍数:

var num = 47;
var result = Math.floor(num / 10) * 10; // 结果为 40

这个方法会将 num 除以 10 后向下取整,再乘以 10 得到最近的 10 的倍数。如果要向上取整到最近的 10 的倍数,可以使用 Math.ceil() 函数。


原文地址: https://www.cveoy.top/t/topic/mlT8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录