C ++ 11 std :: round in <cmath> .
Without this, you can use std :: floor and std :: ceil at the corrected numbers. For instance. std::floor(n * 100 + 0.5)/100 round to two decimal places.
Although it should be noted that rounding is not entirely trivial; There are difficulties, such as the choice of rounding to zero, to negative infinity, rounded to even, etc. If you are writing production programs, make sure you understand the rounding requirements for your domain.
source share