在浮点数指定数字个数显示。
streamsize precision( ) const;
streamsize precision(
streamsize _Prec
);
参数
- _Prec
显示的有效数字个数或数字个数在以后在固定表示形式小数点。
返回值
第一个成员函数返回存储的 显示精度。第二个成员函数中显示精度存储 _Prec 并返回其以前存储的值。
备注
浮点数与 内置的内置的形式显示。
示例
// 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
}
要求
标头: <ios>
命名空间: std