头文件#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