Skip to main content

Math.ceil() Method in JS – How to Round Up Numbers

Whenever you invoke Math.ceil(), the method rounds up its argument to the nearest integer.

note

Syntax of the Math.ceil() Method

Math.ceil() accepts only one argument. Here is the syntax:

Math.ceil(value);

The value argument represents the number you wish to round up to the nearest integer.

note
  • Suppose the value argument is already an integer. In that case, Math.ceil() will return the same number.
  • Math.ceil() is equivalent to -Math.floor(-value).

Examples

Below are examples of the Math.ceil() method.

How to round up 9 to the nearest integer

Math.ceil(9);

// The invocation above will return: 9

Try it on StackBlitz

How to round up 9.999 to the nearest integer

Math.ceil(9.999);

// The invocation above will return: 10

Try it on StackBlitz

How to round up -9.999 to the nearest integer

Math.ceil(-9.999);

// The invocation above will return: -9

Try it on StackBlitz

The snippet above returned -9 because -9 is the integer directly above -9.999 on the number line. In other words, -9 is greater than -9.999. But -10 is less than -9.999.

How to round up 0.91 to the nearest integer

Math.ceil(0.91);

// The invocation above will return: 1

Try it on StackBlitz

How to round up 0.01 to the nearest integer

Math.ceil(0.01);

// The invocation above will return: 1

Try it on StackBlitz

How to round up 0 to the nearest integer

Math.ceil(0);

// The invocation above will return: 0

Try it on StackBlitz

tip

Overview

This article discussed what JavaScript's Math.ceil() method does. We also used examples to see how it works.

Tweet this article