By using unsetf()
, you are telling cout
to use its default formatting for floating-point values. Since you want an exact number of digits after the decimal, you should be using setf(fixed)
or std::fixed
instead, eg:
double a = ...;
std::cout.setf(std::fixed, ios::floatfield);
std::cout.precision(5);
std::cout << a;
.
double a = ...;
std::cout.precision(5);
std::cout << std::fixed << a;