Help me understand Modulo Operation

please help me understand. why is (2 % 5) giving me the outcome 2.
from what i understand is that this operator gives the rest number of a division. but when i divide this number by 5 its 0.4 with a rest of 0 right?
i am not getting this could someone please explain.

2 = 0 * 5 + 2, therefore (2 / 5 = 0) and (2 % 5 = 2).
dividend = quotient * divisor + remainder, therefore (dividend / divisor = quotient) and (dividend % divisor = remainder), where |remainder| < |divisor|.
thank you Helios for taking your time to help me. i have done only basic school and was really bad at it not understanding much and English is not my native language. I am a old man realized at an old age that i wanted to know more :D So i picked up programming. You probably think why this idiot think he can learn programming. But i have found this love for learning although i am a really bad learner i still have the feeling that i need to learn :D
That said:P i do not really understood from what you are trying to tell me :P
If for example (15%2) i know the outcome is 1 cause it can go 7 times in 15 what is then 14 rest 1. but i do not see how this 1%2 gives 1 i do not follow what is happening could you please try to explain it a little more.

when i divide this number by 5 its 0.4 with a rest of 0 right?
No, it's not the rest it is actually the result of the integer division.

A modulo operation can be expressed as:

y % x => y - ((y / x) * x)

The integer division (i.e. no floating point numbers are involved) omits the digits. Therefore that expression works.
Thank you for your time people :D
when i divide this number by 5 its 0.4 with a rest of 0 right?
No. You're missing the fact that all the numbers (the divisor, quotient, dividend and remainder) are all integers.

i do not see how this 1%2 gives 1
1/2 = 0, with a remainder of 2. Put another way, 1 = 2*0 + 1.

You probably think why this idiot think he can learn programming
You're never too old to learn to program! :)
excellent thanks. i know i just wish i was a bit sooner with seeing the importance of learning at a young age instead of playing and doing nothing:P
Topic archived. No new replies allowed.