Displaying floating-point values in system default, scientific and fixed formats : cout float « Development « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
using std::scientific;

int main()
{
   double x = 0.001234567;
   double y = 1.946e9;

   cout << "Displayed in default format:" << endl << x << '\t' << y << endl;

   cout << "\nDisplayed in scientific format:" << endl << scientific << x << '\t' << y << endl;

   cout << "\nDisplayed in fixed format:" << endl << fixed << x << '\t' << y << endl;
   return 0;
}
Displayed in default format:
0.00123457      1.946e+009

Displayed in scientific format:
1.234567e-003   1.946000e+009

Displayed in fixed format:
0.001235        1946000000.000000








5.6.cout float
5.6.1.Displaying floating-point values in system default, scientific and fixed formats
5.6.2.ios::right|ios::scientific|ios::showpoint
5.6.3.Displaying numbers in scientific notation
5.6.4.Normal (default) mode; only show 5 digits, including both sides of decimal point
5.6.5.Controlling precision of floating-point values