C/C++ 数据精确度的设置
#include<iostream>
#include<iomanip> //此库为代码最后一行快捷设置数据格式需要用的的库
#include<math.h>
using namespace std;
#define PI atan(1.0) * 4
int main(){
cout << "原始数据:" << PI << endl;
cout.precision(2);
cout << "设置有效数位后的数据:" << PI << endl;
cout.setf(ios::fixed);
cout << "设置小数点后有效数位的数据" << PI << endl;
cout << "输出格式已绑定后的数据" << PI << endl;
cout.unsetf(ios::fixed);
cout.precision(6);
cout << "输出格式已恢复默认后的数据" << PI << endl;
cout << "快捷设置输出格式后的数据:" << fixed << setprecision(2) << PI << endl;
#include<iomanip> //此库为代码最后一行快捷设置数据格式需要用的的库
#include<math.h>
using namespace std;
#define PI atan(1.0) * 4
int main(){
cout << "原始数据:" << PI << endl;
cout.precision(2);
cout << "设置有效数位后的数据:" << PI << endl;
cout.setf(ios::fixed);
cout << "设置小数点后有效数位的数据" << PI << endl;
cout << "输出格式已绑定后的数据" << PI << endl;
cout.unsetf(ios::fixed);
cout.precision(6);
cout << "输出格式已恢复默认后的数据" << PI << endl;
cout << "快捷设置输出格式后的数据:" << fixed << setprecision(2) << PI << endl;
return 0;
}