#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//会有四舍五入
double a=3.141592653;
cout << fixed << setprecision(3) << a << endl; // fixed开:3位小数 3.142
cout << setprecision(5) << a << endl; // fixed依旧开:5位小数 3.14159
cout << defaultfloat; // 关闭fixed
cout << setprecision(5) << a; // 默认模式:5位有效数字 3.1416
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: