As shown in the tutorial http://www.cplusplus.com/reference/iomanip/setprecision/
// setprecision example
#include // std::cout, std::fixed
The meaning of precision depends on whether fixed, scientific or default format is used. For fixed format, it's the number of digits after the decimal point. For scientific, it is, too - but there's always exactly one digit before the point; the exponent is used to shift the decimal point into position. For default format, precision specifies the total number of digits printed (roughly; it's a bit more complicated).
For details, see http://en.cppreference.com/w/cpp/io/c/fprintf , in particular the description of %f
, %e
and %g
format specifiers (for fixed, scientific and default format, correspondingly). std::cout << f
is specified to behave as if printf("%.
is called (to the first approximation; the reality is, again, a bit more complicated, but the details are not relevant to the issue at hand), where
is the number specified by setprecision
, and
is one of f
, e
or g
.