c++中 cout precision

#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
    double result1 =sqrt(3.0);
    
    cout<<"对3开方保留小数后0-9位 ,结果如下:\n"<<endl;
    
        for(int i=0;i<=9;i++)
    {
        cout.precision(i);
        cout<< result1 <<endl;
    } 
    
    cout<<"当前的输出精度为:"<<cout.precision()<<endl;
    return 0;

}

/*
对3开方保留小数后0-9位 ,结果如下:

1.7320508075688771932
2
1.7
1.73
1.732
1.7321
1.73205
1.732051
1.7320508
1.73205081
当前的输出精度为:9
请按任意键继续. . .



*/
原文地址:https://www.cnblogs.com/yoyov5123/p/2934491.html