Mega Code Archive

 
Categories / C++ Tutorial / Development
 

Displaying floating-point values in system default, scientific and fixed formats

#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