0.6 --> 0.60

Hello,
I have one array saved in a float with one saved space as 0.60 but when i use the command cout it always comes as 0.6 is there a way i can make the 0 appear at the end?

Hello Nickoblack,

In addition to what Thomas1965 said, look into this link for what is in the "iomanip" header file:

http://www.cplusplus.com/reference/iomanip/

Mostly the part on "setprecision" and at the bottom if the page for "fixed".

Over time I have found this to work the best:

1
2
3
4
5
6
std::cout << std::fixed << std::setprecision(2);
std::cout<<0.60<<std::endl;

or

std::cout << std::fixed << std::setprecision(2) << 0.60;


either way will set the output to two decimal places along with anything that you might do after until you change the number of decimal places or the program ends.

Over time I have found that using std::fixed << std::setprecision(x) to work the best for me. With the std::fixed being necessary to work properly.

Hope that helps,

Andy
Topic archived. No new replies allowed.