Monday, 22 April 2019

math - Integer division with remainder in JavaScript?



In JavaScript, how do I get:




  1. the whole number of times a given integer goes into another?

  2. the remainder?


Answer




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;

No comments:

Post a Comment