Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cmath> ceil() function is used to return the next highest integer value by rounding up the specified number, if necessary. In other words, it rounds the fraction UP of the given number.

Syntax

double ceil (double x);
float ceil (float x);
long double ceil (long double x);
double ceil (double x);
float ceil (float x);
long double ceil (long double x);
//additional overloads for integral types
double ceil (T x);                              

Parameters

x Specify a number.

Return Value

Returns the next highest integer value by rounding UP the specified number, if necessary.

Example:

In the below example, ceil() function is used to round the fraction UP of the specified number.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<ceil(10.5)<<"\n";
  cout<<ceil(-10.5)<<"\n";
  cout<<ceil(0.5)<<"\n";
  cout<<ceil(-0.5)<<"\n";   
  return 0;
}

The output of the above code will be:

11
-10
1
-0

❮ C++ <cmath> Library