2019独角兽企业重金招聘Python工程师标准>>>
1输出精度控制
#include<iostream>
#include <iomanip>//精度控制相关头文件
using namespace std;int main(){streamsize prec=cout.precision(); //获取默认精度 cout<<"default precision size is "<<prec<<endl;cout<<setprecision(3);//重设精度 double x;while(cin>>x){cout<<"the current input x is "<<x<<endl; }cout<<setprecision(prec);//重置默认精度 double temp=1.3333333;cout<<"the value is "<<temp<<endl;cout<<"end input!!!!!!!!!!!"<<endl;system("pause");return 0;
}
输出:
default precision size is 6
1.2345
the current input x is 1.23
123456
the current input x is 1.23e+005
quit
the value is 1.33333
end input!!!!!!!!!!!