#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.1416 30 10000 3.1416
本文介绍如何使用C++标准库中的iomanip头文件来精确控制浮点数的小数点后位数显示,包括设置固定小数点形式、科学计数法及显示小数点后的零等。
3629

被折叠的 条评论
为什么被折叠?



