Floating-Point Numbers, Scientific and Fixed Notation (scientific, fixed) - C++ File Stream

C++ examples for File Stream:cout

Description

Floating-Point Numbers, Scientific and Fixed Notation (scientific, fixed)

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    double x = 0.001234567;
    double y = 1.946e9;

    // display x and y in default format
    std::cout << "Displayed in default format:" << std::endl
              << x << '\t' << y << std::endl;

    // display x and y in scientific format
    std::cout << "\nDisplayed in scientific format:" << std::endl
              << std::scientific << x << '\t' << y << std::endl;

    // display x and y in fixed format
    std::cout << "\nDisplayed in fixed format:" << std::endl
              << std::fixed << x << '\t' << y << std::endl;

    return 0;//from  ww  w .ja  v a 2  s . co m
}

Result


Related Tutorials