頭文件#include<iomanip>
1.需要補零
cout.setf(ios::fixed);
cout<<fixed<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
2.不需補零
(1)末尾零被省略
cout<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
(2)取消設置fixed
cout.unsetf(ios::fixed);
cout<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
頭文件#include<iomanip>
1.需要補零
cout.setf(ios::fixed);
cout<<fixed<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
2.不需補零
(1)末尾零被省略
cout<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
(2)取消設置fixed
cout.unsetf(ios::fixed);
cout<<setprecision(需要精確到小數點后幾位)<<ans<<endl;
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。