Need Help with Mathmatical Javascript statement

W

Wyseguy79

I am looking at a line of code in javascript that I dont understand...

var ad = n % nn;

What I dont understand is what the % represents as a mathmatical
function in javascript.

If anyone could explain what its doing, that would be great.

Thanks.
 
E

Evertjan.

Wyseguy79 wrote on 03 mrt 2006 in comp.lang.javascript:
I am looking at a line of code in javascript that I dont understand...

var ad = n % nn;

What I dont understand is what the % represents as a mathmatical
function in javascript.

If anyone could explain what its doing, that would be great.

read the specs:

result = number1 % number2

The modulus, or remainder, operator divides number1 by number2 and returns
only the remainder as result. The sign of result is the same as the sign of
number1. The value of result is between 0 and the absolute value of
number2.

For example, in the following expression, A (which is result) equals 5.6.

A = 19 % 6.7
 
H

Hal Rosser

Wyseguy79 said:
I am looking at a line of code in javascript that I dont understand...

var ad = n % nn;

What I dont understand is what the % represents as a mathmatical
function in javascript.

If anyone could explain what its doing, that would be great.

It gives the reaminder after dividing n by nn.
10 % 3 returns 1, because when you divide 10 by 3 you get 3 - and a
remainder of 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top