2016-06-22 198 views

回答

5

默认格式不打印尾随零;您需要将浮点格式设置为fixed,另请参阅this reference。所以,你需要的是

cout << setprecision(2) << fixed << 0.999 << endl; 

还要注意setprecision指十进制数字,所以对于1.0则需要setprecision(1)

相关问题