Open In App

JavaScript Math ceil() Method

Last Updated : 15 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

The JavaScript Math.ceil method is used to return the smallest integer greater than or equal to a given number. The ceil() is always used as Math.ceil() since it is a static method of Math.

Syntax:

Math.ceil(value)

Parameters:

This method accepts single parameters as mentioned above and described below:

  • Value: It is the value that is to be tested for Math.ceil.

Return Value:

The Math.ceil() method returns the smallest integer greater than or equal to the given number.

Example 1: In this example, we will get the round-off value of 0.89.

javascript
console.log("Result : " + Math.ceil(.89));

Output
Result : 1

Example 2: When a negative number is passed as a parameter.

javascript
console.log("Result : " + Math.ceil(-89.02));

Output
Result : -89

Example 3: When zero is passed as a parameter.

javascript
console.log("Result : " + Math.ceil(0));

Output
Result : 0

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers:

  • Chrome 51
  • Edge 15
  • Firefox 54
  • Safari 10
  • Opera 38

JavaScript Math ceil() Method - FAQs

What does the Math.ceil() method do in JavaScript?

The Math.ceil() method rounds a number up to the nearest integer greater than or equal to the given number.

Can Math.ceil() handle negative numbers?

Yes, Math.ceil() can handle negative numbers. It rounds negative numbers up towards zero to the nearest integer.

What is the most common use of the Math.ceil() method?

Most Common Use Cases:

  • Rounding up numerical results to the nearest whole number for presentation or further calculation.
  • Ensuring positive integer values in algorithms that require such numbers.
  • Simplifying numerical data for readability and reporting.

Does Math.ceil() work with very large or very small numbers?

Yes, Math.ceil() works with very large or very small numbers, rounding them up to the nearest integer within the limits of JavaScript's number precision.

How does Math.ceil() handle numbers with a fractional part of 0?

If the number has a fractional part of 0 (i.e., it is already an integer), Math.ceil() returns the number unchanged.


Practice Tags :

Similar Reads