Integer division with remainder in JavaScript?

Yarin picture Yarin · Nov 19, 2010 · Viewed 776.7k times · Source

In JavaScript, how do I get:

  1. The whole number of times a given integer goes into another?
  2. The remainder?

Answer

Mark Elliot picture Mark Elliot · Nov 19, 2010

For some number y and some divisor x compute the quotient (quotient) and remainder (remainder) as:

var quotient = Math.floor(y/x);
var remainder = y % x;