As shown in the tutorial http://www.cplusplus.com/reference/iomanip/setprecision/
// setprecision example
#include // std::cout, std::fixed
Behaviour of std::setprecision()
differs depending on the chosen formatting.
std::fixed
make std::setprecision()
refer to how many digits are printed after the decimal point. Before you change the default formatting to std::fixed
, std::defaultfloat
is set, and std::setprecision()
sets the total number of digits to be printed, including the ones both before and after the decimal point.
Compare:
http://www.cplusplus.com/reference/ios/defaultfloat/
http://www.cplusplus.com/reference/ios/fixed/