#include<bits/stdc++.h>
using namespace std;
int main() {
double a = 12.34567;
cout << setprecision(4) << a << endl; //设置总共保留4位数
cout << fixed << a << endl; //设置保留的4位数是小数
cout.unsetf(ios::fixed); //取消设置保留的4位数是小数
cout << a << endl;
return 0;
}
测试结果: