March 1, 2000 - Rounding Numbers Up | WebReference

March 1, 2000 - Rounding Numbers Up

Yehuda Shiran March 1, 2000
Rounding Numbers Up
Tips: March 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

The Math.ceil() method accepts a single numeric argument and returns the next integer greater than or equal to the argument (rounding up). Therefore, the returned value is never less than the argument. Here are a few examples:

Math.ceil(16) == 16
Math.ceil(16.01) == 17
Math.ceil(-15.01) == -15

Let's say you need to fit num1 cars into parking lots, where each parting lot has space for num2 cars. You can use the Math.ceil() method along with a function to calculate the minimum number of parking lots:

function getNumLots(num1, num2) {
  return Math.ceil(num1 / num2);
}