Jump to content

Modulus (Division Remainder)


Shadowing
 Share

Recommended Posts

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

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

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

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
Link to comment
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.

Edited by Shadowing
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...