Ημερήσια αρχεία: 22 Απριλίου 2017


C++ How to make cout not use scientific notation

To force cout to print numbers exactly as they are and prevent it from using the scientific notation, we can use the std::fixed I/O manipulator as follows

#include <iostream>

using namespace std;

int main()
{
    std::cout << "The number 0.0001 in fixed:      " << std::fixed << 0.0001 << endl
              << "The number 0.0001 in default:    " << std::defaultfloat << 0.0001 << endl;

    std::cout << "The number 1000000000.0 in fixed:      " << std::fixed << 1000000000.0 << endl
              << "The number 1000000000.0 in default:    " << std::defaultfloat << 1000000000.0 << endl;
return 0;
}

Output

The number 0.0001 in fixed:      0.000100
The number 0.0001 in default:    0.0001
The number 1000000000.0 in fixed:      1000000000.000000
The number 1000000000.0 in default:    1e+09