c++保留小数后几位
时间:2019-12-02 21:51:39
收藏:0
阅读:348
头文件#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;
原文:https://www.cnblogs.com/Chen3201/p/11973308.html
评论(0)