I have this
double a = 4.0; double b = 2.0; double g = a + b; std::cout << g;
I am getting 6, but I want to get 6.0>
6
6.0>
One way:
#include //... std::cout << std::setprecision(2) << g;
This sets the precision of the output to 2 significant figures.
Edit: as the other answer points out, prepend std::setprecision with std::fixed.
std::setprecision
std::fixed