Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 浮点精度
当我这样做时。cout<<8.0它被打印为8。如何在 c++ 的输出控制台中打印小数点后的整个零,就像8.00000000 我尝试过的那样cout<<setprecision(5)<<(double)8.0;仍在打印8
cout<<8.0
8
8.00000000
cout<<setprecision(5)<<(double)8.0;
使用fixed机械手
fixed
#include <iostream> #include <iomanip> using namespace std; int main() { cout << fixed << setprecision(6) << (double)8 << "\n"; return 0; }
http://ideone.com/ShcNIc
请参阅如何使用 cout 以全精度打印双精度值?
cout.precision(15); cout << fixed << 8.0;