다음을 통해 공유


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

참고 항목

참조

ios_base 클래스

iostream 프로그래밍

iostreams 규칙