c++保留小数后几位

安稳与你 提交于 2019-12-06 08:43:58

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!