Good day to you.
I have been searching information about modulus for days but I found that they all gave different answers (from my opinion .....)
- Code: Select all
$a % $b
Basically, the defination is the remainder when you divide $a by $b.
1) First example from website
- Code: Select all
"what if you take 7/5? If you plug this into the PHP engine, you'll get a decimal number of 1.4. However, if you do 7 modulus 5, you're going to get 2."
I think I can understand this, the result is rounded up to the nearest integer to 2.
2) Second example from book.
- Code: Select all
"27 % 10, answer is 7."
I failed to understand why 27 / 10 and the remainder is 7. Shouldn't it be 2.7 ? Even if it rounds to nearest integer, it should be 2 or 3.
3) Third exmaple from tizag
- Code: Select all
"Perform modulus: 5 % 2 = 1. Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1. "
Again, after dividing 5 by 2, it should be 2.5, how it becomes 1?
I wish to get some advice from you.
Thank you.