Alec Gorge Alec Gorge - 2 years ago 93
Javascript Question

Javascript modulo not behaving

According to Google Calculator

(-13) % 64

According to Javascript (see this JSBin: it is

How do I fix this?

Answer Source
Number.prototype.mod = function(n) {
    return ((this%n)+n)%n;

Taken from this article: The JavaScript Modulo Bug

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download