Reputation: 183
I'm trying to display number in standard notation
for example:
float f = 1230000.76
turns out to be,
1.23e+006
Upvotes: 17
Views: 33198
Reputation: 3423
There are two things found in iomanip that must be included. First is fixed
and the second is setprecision
You need to write:
std::cout << fixed;
std::cout << setprecision(2) << f;
fixed
disables the scientific notation i.e. 1.23e+006 and fixed is a sticky manipulator so you need to disable it if you want to revert back to scientific notation.
Upvotes: 16
Reputation: 29176
Use -
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
before printing out the floating point numbers.
More information can be found here.
You can also set output precision with the following statement -
cout.precision(2);
or simply with -
printf("%.2f", myfloat);
Upvotes: 9