Javatpoint Logo
Javatpoint Logo

C++ Manipulator scientific

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

When we set floatfield to scientific, then floating point values are written using scientific notation; the value is represented always with only one digit before the decimal point, followed by the decimal point and like many decimal digits as the precision field. And finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and three exponential digits.

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 scientific 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