How to round numbers to nearest whole number?

I think I’ve seen similar posts on the forum but I’m still confused because I want to round numbers just like 100.5 to just like 101 because some people in my game have that extra 0.5 in their points leaderstats but I want to make a global points leaderboard but I can’t have doubles in DataStores.

Any simple solution for this?

2 Likes

Yo can do: math.floor(100.2) for example which will return 100.

math.floor(number + 0.5)

will round to the nearest whole number
for example:

function round(num)
    return math.floor(num + 0.5)
end

print(round(3.3)) -- 3
print(round(3.6)) -- 4
7 Likes

You can just do
math.floor or math.ceil

Math.ceil returns to biggest number
sample:
1.1 = 2
math floor returns the less number
sample
1.9 = 1

2 Likes

Thanks for the help, all these solutions worked!

Instead of doing all that math, just simply use the math.round() function.

For example:

print(math.round(50.52))
Output: 51

print(math.round(50.32))
Output: 50