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