Floating-point values in system default, scientific, and fixed formats. : float output « Data Type « C++






Floating-point values in system default, scientific, and fixed formats.

   
#include <iostream>

using std::cout;
using std::endl;
using std::ios;

int main()
{
   double x = .001234567, y = 1.946e9;

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

   cout.setf( ios::scientific, ios::floatfield );
   cout << "Displayed in scientific format:\n" << x << '\t' << y << '\n';

   cout.unsetf( ios::scientific );
   cout << "Displayed in default format after unsetf:\n" << x << '\t' << y << '\n';

   cout.setf( ios::fixed, ios::floatfield );
   cout << "Displayed in fixed format:\n"<< x << '\t' << y << endl;
   return 0;
}
  
    
    
  








Related examples in the same category

1.Set precision for float number
2.Output float number with fixed flag
3.Output float type number with scientific format
4.Change cout width and precision for string and float number output
5.Output float in default floating-point format
6.Controlling precision of floating-point values