Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform an integer division, and separately get the remainder, in JavaScript?

In JavaScript, how do I get:

  1. The whole number of times a given integer goes into another?
  2. The remainder?
like image 753
Yarin Avatar asked Nov 19 '10 18:11

Yarin


1 Answers

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; 
like image 157
Mark Elliot Avatar answered Sep 29 '22 19:09

Mark Elliot