+ 7

[DUPLICATE] How to calculate modulus ?!!

If x = 15%4 then x = ?

13th Jan 2017, 12:03 PM
Hassan Amr
Hassan Amr - avatar
5 Answers
+ 7
what is the meaning of mathfloor ?
13th Jan 2017, 12:51 PM
Hassan Amr
Hassan Amr - avatar
+ 7
Answer 3
4th Mar 2017, 7:18 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 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));
13th Jan 2017, 12:49 PM
visph
visph - avatar
+ 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..
13th Jan 2017, 12:55 PM
visph
visph - avatar
+ 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
13th Jan 2017, 12:15 PM
Nathan
Nathan - avatar