Lua replacement for the % operator

Cyclone picture Cyclone · Mar 14, 2012 · Viewed 69k times · Source

I want to check, if a number is divisible by another number:

for i = 1, 100 do
    if i % 2 == 0 then
        print( i .. " is divisible.")
    end
end

This should work without any problems, but with the Lua in my server the script doesn't run if there is a % in the script... I dont know whats the reason, so is there any "replacement" for that? So I could check the number divsibility?

Thank you.

Answer

lhf picture lhf · Mar 14, 2012

Use math.fmod(x,y) which does what you want:

Returns the remainder of the division of x by y that rounds the quotient towards zero.

http://www.lua.org/manual/5.2/manual.html#pdf-math.fmod