In Lua, how can I tell if a number divides evenly into another number? i.e with no remainder? I’m just looking for a boolean true or false.
12/6 = 2 (true)
18/6 = 3 (true)
20/6 = 3.(3) (false)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Compare the remainder of the division to zero, like this:
The modulus operator (
%) returns the remainder of division. For 12 and 6 it is 0, but for 20 and 6 it is 2.The formula it uses is:
a % b == a - math.floor(a/b)*b