The Title says everything, but i'll explain what is my objective with this.. Example:
local var1 = 1.87 local var2 = 1.16 local var3 = 3 --(somehow, the NumberValues converted into IntValues!) print(var1,var2,var3)
OUTPUT
2 1 3
i don't know if there is a built in function for this.. tell me plz
I think what you're trying to do is round a number to the nearest whole number.
Lua doesn't have this concept exactly built in, but it does have a very similar function. math.floor(x)
is the biggest whole number under x
.
For example, math.floor(1.1)
is 1
and math.floor(2.9)
is 2
.
math.floor
does what you want when the fractional part of a number is between 0 and 1/2, but it goes too low when it's between 1/2 and 1.
To fix, that we use math.floor(x + 0.5)
:
math.floor(1.1 + 0.5) --> 1 math.floor(1.4 + 0.5) --> 1 math.floor(1.5 + 0.5) --> 2 math.floor(1.6 + 0.5) --> 2 math.floor(2.2 + 0.5) --> 2