C++ Manipulator setprecisionC++ 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>. SyntaxParametern: new value for the decimal precision. Return valueThis function returns an object of unspecified type. The setbase function should only be used as a stream manipulator. Data RacesThe stream object on which it is inserted or extracted is modified and concurrent access to the same stream object may introduce data races. ExceptionsObject is in a valid state, if any exception is thrown. Example 1Let's see the simple example to demonstrate the use of setprecision: Output: 3.1416 3.14159 3.14159 3.141590000 Example 2Let's see another simple example: Output: default precision (6): 3.14159 setprecision(10): 3.141592654 max precision:3.141592653589793239 Example 3Let's see another simple example: Output: 2 1.7 1.67 1.667 1.6667 1.66667
Next TopicC++ Manipulator
|