ceil()
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
- GaVi-_3 total contributions
- Christine_Yang271 total contributions
- garanews222 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- StevenSwiniarski475 total contributions
- GaVi-_
- Christine_Yang
- garanews
- christian.dinh
- Anonymous contributor
- StevenSwiniarski
Looking to contribute?
- 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.