2016-06-22 176 views

回答

5

默認格式不打印尾隨零;您需要將浮點格式設置爲fixed,另請參閱this reference。所以,你需要的是

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

還要注意setprecision指十進制數字,所以對於1.0則需要setprecision(1)

相關問題