# Modulus (Division Remainder)

## Recommended Posts

I need help understanding Modulus (division remainder) on the PHP operators page at w3schools I just cant make head or tails out of the results http://www.w3schools...p_operators.asp how does 5%2 return 1 thanks for any help with this

##### Share on other sites

as it is said it is return the remainder of division 5%2 return 14%2 return 08%3 return 2

##### Share on other sites

wierd i still dont understand my understanding of what a remainder is if you devide say 296 / 24 = 12.3 so the remainder is 3

##### Share on other sites

The remainder is what is left from a division when you get an integer as a quotient. If you divide 5/2, the result as a decimal number is 2.5 but when you use the % operator, you get what's left when the result is an integer. If you would do the division 5/2 in paper, in the first part you'd get 2 as a quotient and you'll have 1 for a remainder. In your example (296/24) , 24*12 = 288 and the remainder is the rest (299-288 = 11). I really hope i didn't confuse you more.

##### Share on other sites

If you want an idea of what the modulus does, do a division, then multiply the decimal part by the divisor. If you divide 296 / 24 = 12.33333333... then the remainder is 0.333333333... * 24 = 8 so 296 % 24 = 8 If you learnt to divide in elementary school and try the division on pencil and paper, you'll find that the division naturally leaves the remainder as 8.

##### Share on other sites

wierd i still dont understand my understanding of what a remainder is if you devide say 296 / 24 = 12.3 so the remainder is 3
no. .3 is not the same as the integer value 3. This is basic math. .3 is one 3rd (1/3), and as Ingolme stated, it is 1/3 of the divisor. Which in this case is 8. (24/3 = 8). for further proof of concept, if you take 24 * 12 it will equal = 288. 296 - 288 = 8. Edited by thescientist
##### Share on other sites

To put it another way, 2 goes into 5 two times, with 1 left over, so 5%2 is 1. If you did 8%3, then 3 goes into 8 two times, with 2 left over, so 8%3 is 2.

##### Share on other sites

lol wierd. thanks guys. I dont even know what was going through my head. woke up and took a pill for a head ache about a hour asking this question. i dont know why i was stuck on the decimal haha maybe i should take a break from php for a few days. ive really been hitting it hardif you guys saw the math i was doing yesterday and even later on since i posted this you wouldnt think i would of asked that question lol. I do feel strained atm and have been for a week now. so idk. maybe i had a breakdown or something.