C++,cout输出小数点后指定位

#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;
}

 

posted @ 2017-08-14 07:58  路人姜。  阅读(754)  评论(0编辑  收藏  举报