# How does Modulo work?

• October 18th, 2011, 12:35 PM
Mr.nuub
How does Modulo work?
Hello everyone,

Could someone explain to me how the modulo works. I understand that 6%3=0 because 6/3=2.0 with no remainder.
But I don't understand that 3%6=3 because 3/6=0.5

Is this because 0.5 is not an int and so it gets 0? So 0 * 6 = 0 and it leaves 3? I have no idea how to read this.

I hope someone can help me out with this :)

Thank you
• October 18th, 2011, 02:03 PM
helloworld922
Re: How does Modulo work?
modulo gets the remainder.

It can be read as what is the remainder of 3/6? The answer is 3.
• October 19th, 2011, 12:26 PM
Mr.nuub
Re: How does Modulo work?
Quote:

Originally Posted by helloworld922
modulo gets the remainder.

It can be read as what is the remainder of 3/6? The answer is 3.

Now what is the remainder of 2/18? The answer is 16 with your way of looking at it right? But the correct answer is 2.

I know it is a silly question, but I really need more theory than that single line you gave me.
• October 19th, 2011, 01:04 PM
KevinWorkman
Re: How does Modulo work?
Quote:

Originally Posted by Mr.nuub
Now what is the remainder of 2/18? The answer is 16 with your way of looking at it right? But the correct answer is 2.

Wrong. With "his way of looking at it", the answer is 2. How many times does 18 go into 2? Zero times, with a remainder of 2. Exactly how 6 goes into 3 zero times with a remainder of 3.

Quote:

Originally Posted by Mr.nuub
I know it is a silly question, but I really need more theory than that single line you gave me.

Then you should have thrown together a test program that ran some more examples, or did more division by hand. For example, when you say 3/6 is .5, how are you arriving at that answer?