c++怎样指定小数点后几位

来源:互联网 发布:mac 命令行安装mysql 编辑:程序博客网 时间:2024/05/19 18:43

#include<iomanip>

cout<<"Case "<<count<<": "<<showpoint<<fixed<<setprecision(5)<<temp-1<<endl;

指定小数点后5位

设定为showpoint后,在不必要的时候也显示10进数的小数点以及其后的0 
fixed是显示的数固定小数点表示,不用科学计数法100.00000
scientific是显示的用科学计数法。  1.00000e+002
int main () {  double a, b, pi;  a=30.0;  b=10000.0;  pi=3.1416;  cout.precision (5);  cout <<   showpoint << a << '\t' << b << '\t' << pi << endl;  cout << noshowpoint << a << '\t' << b << '\t' << pi << endl;  return 0;}The execution of this example displays something similar to:30.000  10000.  3.141630      10000   3.1416


0 0
原创粉丝点击