|
ios_base::precisionpublic member function
streamsize precision ( ) const; streamsize precision ( streamsize prec ); Get/Set floating-point decimal precision The first syntax returns the value of the current floating-point precision field for the stream.The second syntax also sets it to a new value. The floating-point precision determines the maximum number of digits to be written on insertion operations to express floating-point values. How this is interpreted depends on whether the floatfield format flag is set to a specific notation (either fixed or scientific) or it is unset (using the default notation, which is neither fixed nor scientific):
This decimal precision can also be modified using the parameterized manipulator setprecision. Parameters
Return ValueThe value set as precision for the stream before the call.Example
The execution of this example displays something similar to:
Notice how the first number written is just 5 digits long, while the second is 6, but not more, even though the stream's precision is now 10. That is because precision with the default floatfield only specifies the maximum number of digits to be displayed, but not the minimum. The third number printed displays 10 digits after de decimal point because the floatfield format flag is in this case set to fixed. See also
|