Zer0Cactus
(Zer0Cactus)
April 12, 2020, 10:07pm
#1
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
jrmblox
(jrmblox)
April 12, 2020, 10:08pm
#2
Yo can do: math.floor(100.2) for example which will return 100.
Kacper
(Kacper)
April 12, 2020, 10:10pm
#3
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
varjoy
(variable)
April 12, 2020, 10:13pm
#4
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
Zer0Cactus
(Zer0Cactus)
April 12, 2020, 10:31pm
#5
Thanks for the help, all these solutions worked!
7u5a
(7u5a)
July 17, 2021, 8:40am
#6
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