使用cout打印精度为4的double

URL*_*L87 12 c++ precision double cout

可能重复:
在C++中将double转换为固定小数点

假设,我有double a = 0 ,我想打印它0.0000 .

我试过这个:

cout.precision(4) ; 
cout<<a<<endl ; 
Run Code Online (Sandbox Code Playgroud)

但它0作为输出勉强.

SeM*_*eKh 27

试一试:

#include <iomanip>
...
cout << fixed << setprecision(4);
cout << a << endl;
Run Code Online (Sandbox Code Playgroud)

看到这里.