Hello, i am using a math.random(50,100) but im wondering how i can round to the closest 10 after the random number is decided?
Thanks for any help
Hello, i am using a math.random(50,100) but im wondering how i can round to the closest 10 after the random number is decided?
Thanks for any help
Divide the number by 10, use math.round on that number then multiply it by 10
local function RoundToClosest(Number,Snap)
return math.round(Number/Snap)*Snap
end
print(RoundToClosest(6,10)) -- 10
print(RoundToClosest(15,10)) -- 20
print(RoundToClosest(4000,9)) -- 3996
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.