打印双精度4使用cout [英] print double with precision 4 using cout
本文介绍了打印双精度4使用cout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
将C ++中的双精度值转换为固定的小数点
假设我有 double a = 0
,我想打印为 0.0000
。
Suppose , I have double a = 0
and I want to print it as 0.0000
.
我已经尝试过:
cout.precision(4) ;
cout<<a<<endl ;
,但它将 0
作为输出。
推荐答案
只需尝试:
#include <iomanip>
...
cout << fixed << setprecision(4);
cout << a << endl;
请参阅这里。
这篇关于打印双精度4使用cout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文