C++ iomanip fixed Manipulator
Example
Print a decimal number with and without fixed:
double x = 9.5;
cout << x << "\n";
cout << fixed << x;
Definition and Usage
The fixed manipulator prints decimal numbers with a fixed number of decimals (digits after the decimal point). The numbers are never printed in scientific notation.
The default is 6 decimals. Use setprecision() to choose another number of decimals. fixed keeps working for all the numbers printed after it.
The fixed manipulator is defined in the <ios> header file.
Tip: Use fixed together with setprecision(2) to print prices, like 9.50. Learn more in the Decimal Precision chapter.
Syntax
cout << fixed;
You do not need to include <iomanip> to use fixed. 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. |
|---|