Number.prototype.mod = function (n) {
return ((this % n) + n) % n;
};
Taken from this article: The JavaScript Modulo Bug
More Related Contents:
- How to perform an integer division, and separately get the remainder, in JavaScript?
- Why does Math.round(1.53*20)/20 = 1.55? How does this actually work?
- Modulo operator
- What exactly does Math.floor do?
- how to use if(math.random == 50)? [closed]
- What is the quickest way to subtract a variable from a number and set the variable?
- How to force JS to do math instead of putting two strings together [duplicate]
- Evaluating a string as a mathematical expression in JavaScript
- How to find prime numbers between 0 – 100?
- How to transform black into any given color using only CSS filters
- Calculate date from week number in JavaScript
- Remove insignificant trailing zeros from a number?
- JavaScript exponents
- Is there a way to calculate 3D rotation on X and Y axis from a 4×4 matrix
- Mixing two colors “naturally” in javascript
- In JavaScript, why does zero divided by zero return NaN, but any other divided by zero return Infinity?
- How can I convert numbers into scientific notation?
- How can I get sin, cos, and tan to use degrees instead of radians?
- How can I round down a number in Javascript?
- How to round up to the nearest 100 in JavaScript
- Write a truly inclusive random method for javascript
- Representing Points on a Circular Radar Math approach
- Why is math.max() returning NaN on an array of integers?
- Javascript: Round up to the next multiple of 5
- Rounding numbers to 2 digits after comma
- Make a number a percentage
- JavaScript: Round to a number of decimal places, but strip extra zeros
- Display Good-looking Math Formula in Android
- How to calculate rotation angle from rectangle points?
- Javascript: PI (π) Calculator