**JavaScript**and other programming languages used in

**Web Design**(and other applications) is the modulo operator represented by the percent sign (%).

In

**JavaScript**(and most C based languages) the Arithmetic operators are the following:

- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
**Modulus: %**- Increment (x=x+1): ++
- Decrement (x=x-1): --

In mathematics the modulo operator basically finds the remainder, or modulus, of a number after it has been divided by a second number. So 10 % 3 = 1 reads 10 modulo 3 equals 1 and means that after 10 has been divided by 3 there is a remainder of 1 that cannot be divided by 3 without resulting in a floating point or decimal number. Here are a few examples:

- 57 % 2 = 1
- 75 % 10 = 5
- 33 % 3 = 0
- 4 % 4 = 0
- 0 % 2 = 0
- 2 % 0 = error: illegal division by zero
- 185 % 60 = 5

So how can you use this operator practically? Well, the previous examples are good and there are many more. However, the most common use for modulo is to determine whether a number is even or odd using the simple formula:

if x % 2 = 0 then "number is even"

else if x % 2 = 1 then "number is odd".

Some other uses are:

- to determine perfect squares
- making a clock that counts hours, minutes, and seconds (x % 60 = sec; Math.floor(x/60) % 60 = min)
- angle calculations (x % 360)
- non-destructive function for cryptology
- getting the decimal part of a number (x % 1)
- getting the day of the week from the day of the year ((x+offset) % 7)

I hope this tutorial has shown you how useful modulo can be and that you can use this in your programming.

Your post was well detailed and I like it. I appreciated it. Thank you for sharing.

ReplyDeletephilippine seoNicely said.. :) Appreciate.will help up a lot in need.Thanks for the post.

ReplyDeleteProfessional business web design

Small business website houston

Hi,In the area of Web Design Cochin, a client always faces difficulty understanding the web designer’s language. The reason being client speaks a layman language and designer speaks his designing language.Thanks...

ReplyDeleteHi… by the look of your website I gather that you are a professional. Can you help me make money, blogging? I have a few sample articles. Can I send it to you for your review? I have already begun posting my skills on sites like selling my logo design,eye catching logo, and www.gicree.com. Quite a number of buyers have responded. I like to post my blogs on other marketplaces too. Do you have any suggestions?

ReplyDelete