hi when i try to get a position of something it just has a bunch of decimals behind it is there a way to round this so it doesnt have these decimals?
COMMUNITY QUESTION
How do you round numbers to nearest whole number in lua?
1 answer
you can use math.floor or math.ceil
math.floor will round a number down
math.ceil will round a number up
Examples:
print(math.floor(8.793186816)) --> 8
print(math.ceil(8.4391595)) --> 9
So what we do to round it up to the nearest whole number is we add 0.5 to it(if your'e using math.floor) but if you're using math.ceil then subtract 0.5
print(math.floor(8.793186816 + 0.5)) --> 9
print(math.ceil(8.4391595 - 0.5)) --> 8
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
math.floor rounds down, math.ceil rounds up. You could build a custom function for this.
math.round