次の方法で共有


ios_base::precision

Specifies the number of digits to display in a floating-point number.

streamsize precision( ) const; 
streamsize precision(
   streamsize _Prec
);

Parameters

  • _Prec
    The number of significant digits to display, or the number of digits after the decimal point in fixed notation.

Return Value

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.

Remarks

Floating-point numbers are displayed in fixed notation with fixed.

Example

// 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
}

31.3
31.312

Requirements

Header: <ios>

Namespace: std

See Also

Concepts

ios_base Class

ios_base Members

iostream Programming

iostreams Conventions