show 8 as 8.00

Without using showpoint and setprecision(3), how can i show 8 as 8.00?

so far i am using:

1
2
int x = 8;
cout << (float) x / 100.0f << endl;
that prints 0.08.

This seems fairly simple, have you tried it?

cout << x << ".00" << endl;
Last edited on
I will never have a fixed value.


x could be 289898, or 288, or 56884, or 200 ...

I need to be able to write x as thousands or hundreds, tens or even ones!

2898.98, or 2.88, or 568.84 or 2.00

also
 
cout << dec << x << endl;

means the same thing as:
 
cout << (float)x / 100.0f << endl;
 
std::cout << std::dec << ( x / 100 ) << '.' << std::setw( 2 ) << std::setfill( '0' ) << ( x % 100 ) << std::endl;


is one way.

Topic archived. No new replies allowed.