ceil()
Christine_Yang271 total contributions
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
:
All contributors
- Christine_Yang271 total contributions
- garanews222 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- StevenSwiniarski474 total contributions
- GaVi-_3 total contributions
- Christine_Yang
- garanews
- christian.dinh
- Anonymous contributor
- StevenSwiniarski
- GaVi-_
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.