Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is it possible to round a number?

Asked by 5 years ago

In my script i am making a difference between two différents values, but the problem is that there are a lot of decimals and this is what ruins my script, so if someone knows a possible way of rounding Numbers i would appreciate it.

2 answers

Log in to vote
2
Answered by
Avigant 2374 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can call math.floor() to round a number towards negative infinity, or math.ceil() to round a number towards positive infinity. Try calling math.floor() on the number + 0.5 if you'd like to round 0.1-0.5 towards negative infinity, and 0.6-0.9 towards positive infinity (though this won't work as expected with numbers bigger than 2^53 - 1).

0
thx ItalianEnderman37 7 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This is what you do.

local Number = 5.7

print(math.ceil(Number)) -- prints 6
print(math.floor(Number)) -- prints 5

Answer this question