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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel
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);
}


People who read this tip also read these tips:

Look for similar tips by subject:



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Performance Optimizations for High Speed JavaScript · Advanced Web Performance Optimization · Simple Comments Meets OpenID
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Extending Telephony: VoIP Call Recording for Business · U-Verse for Business Has Wi-Fi Perks · Lian-Li Launches New Power Supply Line, Rack Mount Kit and Fan Blower