Javatpoint Logo
Javatpoint Logo

C++ Manipulator setprecision

C++ manipulator setprecision function is used to control the number of digits of an output stream display of a floating- point value.

This manipulator is declared in header file <iomanip>.

Syntax

Parameter

n: new value for the decimal precision.

Return value

This function returns an object of unspecified type. The setbase function should only be used as a stream manipulator.

Data Races

The stream object on which it is inserted or extracted is modified and concurrent access to the same stream object may introduce data races.

Exceptions

Object is in a valid state, if any exception is thrown.

Example 1

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

Output:

3.1416
3.14159
3.14159
3.141590000

Example 2

Let's see another simple example:

Output:

default precision (6): 3.14159
setprecision(10): 3.141592654
max precision:3.141592653589793239

Example 3

Let's see another simple example:

Output:

2
1.7
1.67
1.667
1.6667
1.66667
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