JavaScript divide integer | Round up/down examples code

How to do integer division in JavaScript where output should be in int not float?

Dividing integer is very easy in JavaScript, but some time you will get the output in floating point. To get eliminate floating point you can use math floor method.

Normal division

Complete code JavaScript integer division round up

Output: division without decimal

JavaScript divide integer Round

Round UP Example

Use JavaScript ceil() Method Round a number upward to its nearest integer.

Output: 46

Round Down example

Use the JavaScript floor() Method to Round a number down to its nearest integer:

Output: 45

Q: How to do Integer division with remainder in JavaScript?

Answer: For some number y and some divisor x compute the quotient (quotient) and remainder (remainder) as:

Do comment if you have any doubts and suggestion on this tutorial.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.