C++ std::ceil — rounding up

In C++, std::ceil rounds toward positive infinity. The ceiling of 2.3 is 3, the ceiling of −2.3 is −2, and 2 stays 2.

A simple example

std::ceil

  1. Start with 2.3
  2. Do this Round upward to a whole number
  3. Result 3
Two is below 2.3. Three is the first whole number at or above it.
lesson.cpp
#include <iostream>
#include <cmath>

int main() {
    std::cout << (std::ceil(2.3)) << '\n';
}
Output
3