ceil()
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_Edouble 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
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C++ on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours