Computer >> Computer tutorials >  >> Programming >> Javascript

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


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