Javatpoint Logo
Javatpoint Logo

C++ Manipulator fixed

C++ manipulator fixed function is used to set the floatfield format flag for the str stream to fixed.

When we set floatfield to fixed, then floating point values are written using fixed notation; the value is represented with exactly as many digits in the decimal part as specified by the precision filed (precision) and with no exponent part.

C++98

The floatfield format flag is a selective and a toggle flag: it can take one, both or none of the following values as given below -

Flag value Effect when set
Fixed write floating-point values in fixed-point notation
scientific write floating-point values in scientific notation.
(none) write floating-point values in default floating-point notation.

C++11

The floatfield format flag is a selective and a toggle flag: It can take any of the following values, or none as given below-

Flag value Effect when set
Fixed write floating-point values in fixed-point notation.
scientific write floating-point values in scientific notation.
hexfloat write floating-point values in hexadecimal format.
The value of this is the same as (scientific|fixed)
defaultfloat write floating-point values in default floating-point notation. This is the value by default (same as none, before any other floatfieldbit is set).

Syntax

Parameter

str: stream object whose format flag is affected.

Return value

It returns argument str.

Data Races

Data races may cause when modifies str concurrent access to the same stream object.

Exceptions

str is in a valid state, if an exception is thrown.

Example 1

Let's see the simple example to demonstrate the use of fixed manipulator:

Output:

The number 0.01 in fixed:      0.010000
The number 0.01 in scientific: 1.000000e-02
The number 0.01 in hexfloat:   0x1.47ae147ae147bp-7
The number 0.01 in default:    0.01
Parsing 0x1P-1022 as hex gives 0

Example 2

Let's see another simple example:

Output:

default:
3.1416
2006
1e-10

fixed:
3.14159
2006.00000
0.00000

scientific:
3.14159e+00
2.00600e+03
1.00000e-10

Example 3

Let's see another simple example:

Output:

The number 0.01 in fixed:      0.010000
The number 0.01 in scientific: 1.000000e-02
The number 0.01 in hexfloat:   0x1.47ae147ae147bp-7
The number 0.01 in default:    0.01
Parsing 0x1P-1022 as hex gives 0
Next TopicC++ Manipulator





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA