【发布时间】:2013-09-26 17:48:21
【问题描述】:
这可能与this question 重复,但我认为它实际上没有得到正确回答。观察:
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
float p = 1.00;
cout << showpoint << setprecision(3) << p << endl;
}
输出:1.00
现在如果我们将该行更改为:
cout << fixed << showpoint << setprecision(3) << p << endl;
我们得到:1.000
如果我们使用固定的“相反”,我们会得到完全不同的东西:
cout << scientific << showpoint << setprecision(3) << p << endl;
输出:1.000e+00
在设置fixed 后,我怎样才能回到第一个版本的行为?
【问题讨论】:
标签: c++ floating-point cout iomanip