c++中控制输出精度的几种方式

//控制输出精度;可以用iostream中的precision或是用iomanip中的setrecision;
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    float a=4.5891589;
	//cout<<fixed;
	//cout<<setprecision(3)<<a<<endl;

    cout.precision(2);//默认模式下,它指的是显示的总位数;
    cout<<a<<endl;
    
    cout.setf(ios_base::fixed);//定点计数法与科学计数法的精度指小数点位数;
    
    cout<<a<<endl;
	
    return 0; 
} 
原文地址:https://www.cnblogs.com/zhuy/p/2611178.html