Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to round a number?

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

✓ Accepted answer

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).

1 comment

0

thx

This is what you do.

local Number = 5.7

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

This discussion is preserved as it was. New answers, comments, and votes are closed.