#include <iostream>
#include <iomanip>//需要添加此头文件
using namespace std;
int main()
{
    float a=0.20001;
    float b=2;
    cout<<setprecision(2)<<a<<endl;//输出小数点后两位,0会舍去
    cout.setf(ios::fixed);
    cout<<fixed<<setprecision(2)<<b<<endl;//补零
    return 0;
}

 

相关文章: