ceil()

Anonymous contributor's avatar
Anonymous contributor
Published Jul 16, 2021Updated Jul 31, 2023
Contribute to Docs

The ceil() function returns the next whole number that is greater than or equal to the argument.

Syntax

std::ceil(n);

Argument must be a double/float/long double, and the return value will be same type.

Example

Use ceil() to round up some math constants:

#include <iostream>
#include <cmath>
int main() {
double pi = M_PI;
double e = M_E
double a;
double b;
a = std::ceil(pi);
b = std::ceil(e);
std::cout << "Pi rounded up is " << a << "!\n";
std::cout << "e rounded up is " << b << "!\n";
}

This results in the following output:

Pi rounded up is 4!
e rounded up is 3!

Codebyte Example

Use ceil() function to round up the double 12.3456:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C++ on Codecademy