Shadowing Posted January 6, 2012 Share Posted January 6, 2012 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 Link to comment Share on other sites More sharing options...
birbal Posted January 6, 2012 Share Posted January 6, 2012 as it is said it is return the remainder of division 5%2 return 14%2 return 08%3 return 2 Link to comment Share on other sites More sharing options...
Shadowing Posted January 6, 2012 Author Share Posted January 6, 2012 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 Link to comment Share on other sites More sharing options...
TheGallery Posted January 6, 2012 Share Posted January 6, 2012 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. Link to comment Share on other sites More sharing options...
Ingolme Posted January 6, 2012 Share Posted January 6, 2012 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. Link to comment Share on other sites More sharing options...
thescientist Posted January 6, 2012 Share Posted January 6, 2012 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2012 Share Posted January 6, 2012 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. Link to comment Share on other sites More sharing options...
Shadowing Posted January 6, 2012 Author Share Posted January 6, 2012 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.