0

# How to calculate the mod "%" operator?

13th Jun 2016, 12:26 AM
Zuher Yassin Saif Ali + 2
var x = 25%4; document.write(x);
13th Jun 2016, 2:30 AM
ZinC + 1
% operator is used to get remainder of the value ie: if 10%2 remainder 0 will be printed. u can use above operator as: Var a=10; Var b=2; Var c=a%b; document write(c); Or Var a=10%2; document.write(a);
13th Jun 2016, 3:12 AM
sreeraj thampan 0
thank you...
13th Jun 2016, 6:17 PM
Zuher Yassin Saif Ali 0
The modulus operator is very different from division. it does divide, but that number is discarded, whatever is left is printed. in the example of 25%7 we get this; 25/7 does not give a whole number, 21/7 is the closest since we cant increase the starting value of 25. this results in 3, but is discarded. 25-21 is all that matters here, and the answer to that is 4. this can be used to calculate for example; the number of leftover days in a year when you divide the days in a year (365) by the number of weeks in a year (52). 365%52 becomes 364/52 to make the result a whole number. 365-364=1, in this case 1 is printed. Hope this helps:)
20th Jun 2016, 1:17 AM
Utpal Kumar 