ios_base::precision
Specifies the number of digits to display in a floating-point number.
streamsize precision( ) const;
streamsize precision(
streamsize _Prec
);
매개 변수
- _Prec
The number of significant digits to display, or the number of digits after the decimal point in fixed notation.
반환 값
The first member function returns the stored display precision. The second member function stores _Prec in the display precision and returns its previous stored value.
설명
Floating-point numbers are displayed in fixed notation with fixed.
예제
// ios_base_precision.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
float i = 31.31234F;
cout.precision( 3 );
cout << i << endl; // display three significant digits
cout << fixed << i << endl; // display three digits after decimal
// point
}
요구 사항
Header: <ios>
네임스페이스: std