cout输出小数位数

#include <iostream>
#include <iomanip>
/*
需要头文件:"iomanip"
iomanip表示:
io manipulator
*/
using namespace std;

int main()
{
    float a = 0.123000789;
    cout.setf(ios::fixed);//打开自动补位
    cout << "a=" <<fixed<< setprecision(5) << a <<endl;
    cout.unsetf(ios::fixed);//关闭自动补位
    cout << "a=" << setprecision(5) << a <<endl;
}

 

posted on 2018-03-25 13:45  血腥刽子手  阅读(227)  评论(1编辑  收藏  举报

导航