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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...