+ 7
[DUPLICATE] How to calculate modulus ?!!
If x = 15%4 then x = ?
5 Answers
+ 7
what is the meaning of mathfloor ?
+ 7
Answer 3
+ 4
if x = a % b
then x = a - ( b * Math.floor( a / b ) )
Try this:
function w(t) { document.write(t+'<br>'); }
w(15%4);
function m(a,b) { return a-(b*Math.floor(a/b)); }
w(m(15,4));
+ 3
Math.floor() is a javascript function which return the integer value, rounding it with the 'floor' value:
1.3 becomes 1,
1.7 becomes 1...
It keep the entire part of a floating point number, without rounding to 'top' ( superior ) integer value..
+ 1
Some calculators have a 'remainder' function, this is the same as the modulus function ('%'). It gives you the remainder after an integer division.
Using a slightly different example:
Real number division, 14.0 / 4.0 is 3.5
Integer division, 14 / 4 is 3 with a remainder of 2
So, in code, 14/4 will give you 3 and if you want the remainder, use 14%4 which gives you 2



