Possible Duplicate:
How do I print a double value with full precision using cout?
float a = 175.;
cout << a;
如果我运行之前的代码,我只会得到 175,我怎么能用(例如)3 个小数位计算出这个数字,即使它们是零。我怎样才能打印“175.000”?!
最佳答案
您需要 std::fixed
和 std::setprecision
:
std::cout << std::fixed << std::setprecision(3) << a;
这些需要以下标题:
#include <iomanip>
https://stackoverflow.com/questions/14677448/