0
How to calculate the mod "%" operator?
4 Réponses
+ 2
var x = 25%4;
document.write(x);
+ 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);
0
thank you...
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:)