Reputation: 1
I would like to round a number according to the following pattern
e.g 1246 to 1250 e.g 1234 to 1230
As far as I know in java there is math.round(1245,10) to do that. How can I do that in lua?
I tried it with math.floor an ceil.
Upvotes: -1
Views: 349
Reputation: 1554
Transform your value to match your scale (e.g., divide by 10), round it (floor + 0.5), transform back.
function round(value, scale)
return math.floor(value / scale + 0.5) * scale
end
Upvotes: 3