今天閑來無事,敲有如下簡代碼:
double t=58.265987415322;
cout<<t<<endl;
顯示結果為:58.26599,查閱資料才知道
正確操作應是這樣:
#include <iostream>#include<iomanip>using namespace std;void main(){ double t = 2.1111111128796895; cout << t << endl;//默認輸出小數點后面5位,且第6位四舍五入 cout << setPRecision(15) << t << endl;//表示共輸出15位數字 cout <<fixed<< setprecision(15) << t << endl;//表示輸出小數點后面15位 system("pause");}雖然簡單,確實我們平時編寫小程序,所不常見的。值得注意!
新聞熱點
疑難解答
圖片精選