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

JavascriptWeb DevelopmentFront End Technology

Use the % operator to get the remainder after integer division.

Example

You can try to run the following to perform integer division and get the remainder in JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var x = 10;
         var y = 25;

         var quotient = Math.floor(y/x);
         var remainder = y % x;
         document.write(remainder);
      </script>
   </body>
</html>

Output

5
raja
Published on 03-Feb-2018 12:18:49
Advertisements