Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

math - Lua replacement for the % operator

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.

question from:https://stackoverflow.com/questions/9695697/lua-replacement-for-the-operator

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...