C++ iomanip scientific Manipulator
Example
Print a large and a small number in scientific notation:
double big = 1234567.0;
double small = 0.00042;
cout << scientific << big << "\n";
cout << small;
Definition and Usage
The scientific manipulator prints decimal numbers in scientific notation. For example, 1.234567e+06 means 1.234567 times 10 to the power of 6, which is 1234567.
The default is 6 decimals. Use setprecision() to choose another number of decimals. scientific keeps working for all the numbers printed after it.
The scientific manipulator is defined in the <ios> header file.
Tip: Scientific notation is useful for very large and very small numbers.
Syntax
cout << scientific;
You do not need to include <iomanip> to use scientific. It is available when you include <iostream>.
Parameter Values
None.
Technical Details
| Returns: | A reference to the stream (you do not use it directly). It changes all the decimal numbers printed after it. |
|---|