 # using lua to take 2.52235 to just 2

Im making a script that takes the users time and gives them skill points based on it. I have a timer where when they join, every min they are in it adds to there time that is stored in a sql table. Now i take the time and divided it by 3600, aka a hour of play time, and it gives them there skill point. The problem is that its never a even number, its always some decimal. I need it to just everything before the decimal, and i dont wanna round it using math.Round…

Use math.Floor.

math.Round( num ) would work.

Thank you both your the input, its working fine now!

math.round would round it up.

2.52235 would be 3 wouldnt it?

But he wants it rounded down.

local num = tostring(2.52235)
num = string.Explode(".", num)
num = tonumber(num)

Or you could just use math.Floor? math.ceil rounds up, math.floor rounds down, math.Round rounds to whichever is nearest.

That’s a ridiculous solution; I love it

Why not

``````
local num = tonumber(string.Explode(".", tostring(2.52235)))

`````` That would return a table.

[lua]
math.Floor(2.52235)
[/lua]

Well, I don’t know Lua :3:

Changed it, is that better?

Edited:
I get the feeling it should be , not . Are Lua tables 0 or 1 based?

Rather complex when you could just use the rounding functions. Maybe if he wanted 2.52 or something.

1 is the first index in lua.

And why does this thread have so many replies? The answer was given in the first post…

math.floor(2.52235100)/100
> print(math.floor(2.52235
100)/100)
2.52

Although theres probably another nother nother way, why ofcourse there ! local num = tonumber(string.Explode("", tostring(2.52235))…string.Explode("", tostring(2.52235))…string.Explode("", tostring(2.52235))…string.Explode("", tostring(2.52235)))

Seriously

Well there you go, I learned something today

local num = tonumber(string.sub(tostring(2.52235), 1, 4));

Thats too short though :C

I never programmed LUA, but I have a faster way.

``````
local numba = num -(num%1)

``````

I can’t believe all you people forgetting about modulus.