+ 1
how I can use %
6 Answers
+ 5
% (modulus) gives you the remainder of the euclidian division.
For example:
60%7 = 4 (since 60 = 8*7 + 4)
x%2 equals 0 if x is even, and 1 if it is odd
x%10 gives you the last digit
x%100 gives you the last two digits
+ 1
For example if you have a number between 0 and 99 but just want zu have the last digit. So You do like "var last_digit = number%10 ;"
+ 1
% gives the remained of two numbers
+ 1
% is a modulus operator.
It will give you the remainder of two numbers.
Example : 5%2 will give you 1 as remainder
and 29%3 will give you 2 as remainder.
0
just take a no. for example-32 followed by % sign followed by the no. by which you want to divide it let's take 6,it will show the reminder as result(res=2)
0
It's useful if you want an algorithm that find a number that is multiple of another number.
eg. document.write all the numbers multiple of 5.
X = a%5;
if (X = 0) than document.write (a);
as you can see, if the result of modulus is 0 the number is multiple of 5.