ios_base::precision
streamsize precision ( ) const; streamsize precision ( streamsize prec ); | ios_base |
cplusplus.com |
Get/Set floating-point decimal precision.
The first syntax returns the value of the current precision.
The second syntax sets a new value for the floating-point precision.
The precision determines the maximum number of digits that shall be output
on insertion operations to express floating-point values, counting both
the digits before and after the decimal point.
Parameters.
Return Value.
The format flags of the stream before the call.
Example.
// modify precision #include <iostream> using namespace std; int main () { double f = 3.14159; cout.precision(5); cout << f << endl; cout.precision(10); cout << f << endl; return 0; }The execution of this example shall display:
See also.
flags,
width
ios_base class