C++ Math ceil()

Last Updated : 21 May 2026

Math ceil() Function

In C++, the ceil() function is defined in the <cmath> header file and is used to round a number upward to the nearest integer value that is not less than the given number. It always rounds toward positive infinity.
The ceil() function supports float, double, and long double values. It is commonly used in mathematics, graphics programming, scientific calculations, and applications where upward rounding is required.

For example

Syntax

It has the following syntax.

Parameters

x : It is the value that rounds to the nearest integer.

Return value

It returns the smallest integer value not less than x.

Examples of the List ceil() Function

Here, we are going to discuss several examples to demonstrate the List ceil() Function Function.

Example 1: Round a Positive Number Upward Using ceil()

This example demonstrates how the ceil() function rounds a positive floating-point number upward to the nearest integer.

Output:

Initial value of x is :9.2
final value of x is :10   

Example 2: Round a Negative Number Using ceil()

This example demonstrates how the ceil() function behaves when the input value is negative.

Output:

Initial value of x is :-2.2
final value of x is :-2   

Example 3: Use ceil() with an Integer Value

This example demonstrates how the ceil() function behaves when the input value is already an integer. In this case, the same value is returned.

Output:

Initial value of x is : 15
Final value of x is : 15