So I've looked everywhere for a good way to round. I've tried using math.floor and math.ceil, But I can never make it round to the nearest hundredth. Can anyone help?
✓ ANSWER ACCEPTED
How to round to the nearest hundredth?
1 answer
✓ Accepted answer
This isn't too hard. There might be a better way, but as an example, you can use math.floor. This rounds to the nearest whole number:
--// Nearest Whole Number
local function round(num)
return math.floor(num+0.5)
end
You can change this to round to tenths:
--// Nearest Tenth
local function round(num)
return math.floor(((num*10)+0.5))/10
end
And so on:
--// Nearest Hundredth
local function round(num)
return math.floor(((num*100)+0.5))/100
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Thanks! It worked! I'm not very good at math...
Good answer. You can generalize it with "function round(num, decimals) return math.floor(num*10^decimals+0.5)/10^decimals end" if desired.
Oh, That's pretty cool.