📌  相关文章
📜  四舍五入到最接近的数字 lua 代码示例

📅  最后修改于: 2022-03-11 14:54:54.827000             🧑  作者: Mango

代码示例2
--You can round answers to the nearest multiple of a number
--For example, rounding 13 to the nearest multiple of 3 is 12, since 12 is
--divisible by 3
local number = 15.2
local multiple = 3 --the multiple you choose
print(math.floor(number/multiple+0.5)*multiple --Add 0.5
  
--Or just round to the nearest whole number
print(math.floor(number + 0.5))