modulo function javascript code example
Example 1: js modulo
// The JS % operater is REMAINDER not MODULO
// For modulo behaviour use
function mod(n, m) {
return ((n % m) + m) % m;
}
Example 2: javascript modulo
x = a % b // % is modulo
Example 3: how to find remainder in javascript
var myNum = 10 / 4; // 2.5
var fraction = myNum % 1; // 0.5
myNum = -20 / 7; // -2.857142857142857
fraction = myNum % 1; // -0.857142857142857