std::chrono::round(std::chrono::duration)
Min standard notice:
Header: <chrono>
Returns the value t representable in ToDuration that is the closest to d. If there are two such values, returns the even value (that is, the value t such that t % 2 == 0).
# Declarations
template< class ToDuration, class Rep, class Period >
constexpr ToDuration round( const std::chrono::duration<Rep, Period>& d );
(since C++17)
# Parameters
d: duration to convert
# Return value
d rounded to the nearest duration of type ToDuration, rounding to even in halfway cases.
# Example
#include <chrono>
#include <iomanip>
#include <iostream>
int main()
{
using namespace std::chrono_literals;
std::cout << "Duration\tFloor\tRound\tCeil\n";
for (using Sec = std::chrono::seconds;
auto const d : {+4999ms, +5000ms, +5001ms, +5499ms, +5500ms, +5999ms,
-4999ms, -5000ms, -5001ms, -5499ms, -5500ms, -5999ms})
std::cout << std::showpos << d << "\t\t"
<< std::chrono::floor<Sec>(d) << '\t'
<< std::chrono::round<Sec>(d) << '\t'
<< std::chrono::ceil <Sec>(d) << '\n';
}