C ++ setprecision只切断数字..它不会圆

时间:2016-09-28 08:33:02

标签: c++11

double d = 8.19999999999999999999;  
cout << d  << "\n";
cout << fixed << d  << "\n";
cout << setprecision(15) << d  << "\n";
cout << fixed << setprecision(15) << d  << "\n";

输出

8.2
8.200000
8.199999999999999
8.199999999999999

我可以更改它以便打印

 8.2
 8.200000
 8.200000000000000
 8.200000000000000

代替?

0 个答案:

没有答案