Computing.Net > Forums > Web Development > Operator: Modulus

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Operator: Modulus

Reply to Message Icon

Name: mie2com
Date: December 10, 2006 at 02:30:32 Pacific
OS: WinXP
CPU/Ram: Pentium III
Product: Sony
Comment:

Why does 12 % 5 returns 2? How does it calculate?




Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: December 10, 2006 at 06:53:57 Pacific
Reply:

Why 12 % 5 = 2 ?

12 / 5 = 2, with 2 more left as the remainder

7 % 2 = 1
5 % 5 = 0
5 % 3 = 2

get the idea?

---
Fubar


0

Response Number 2
Name: Laler
Date: December 10, 2006 at 06:57:12 Pacific
Reply:

here's a better explanation http://en.wikipedia.org/wiki/Modulo...

---
Fubar


0

Response Number 3
Name: mie2com
Date: December 10, 2006 at 07:22:28 Pacific
Reply:

I see. Correct me if i'm wrong Laler, but from your example, i think it calculate like this is it?

[Assuming ... is just a whitespace]

.......2
....------
5...|.12.|
.....(10)
......--
...... 2 <-- remainder, rite?
......--

Therefore,
100 % 10 = 0
15 % 8 = 7
28 % 2 = 0
2 % 15 = undefined


0

Response Number 4
Name: Michael J (by mjdamato)
Date: December 10, 2006 at 08:37:07 Pacific
Reply:

All of those are correct, except the last one.

2 % 15 = 2

You can't divide 15 into 2 by any whole numbers, so the answer is 0 with a remainder of 2.

Michael J


0

Response Number 5
Name: mie2com
Date: December 10, 2006 at 08:42:49 Pacific
Reply:

Thanks Laler and Michael J. Now I understand what modulus is.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

PHP to View Windows Event... Cant Access Webpage



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Operator: Modulus

php - Special Operators ( *= ) www.computing.net/answers/webdevel/php-special-operators-/3051.html

What operating system support PHP www.computing.net/answers/webdevel/what-operating-system-support-php/3067.html

!= operator is not working www.computing.net/answers/webdevel/-operator-is-not-working/4263.html