#include <iostream> #include <Windows.h> using namespace std; int main(void) { double value = 12.3456789; // cout默认输出6位有效数字 cout << value << endl; // 修改cout的输出精度,设置成输出4位有效数字 cout.precision(4); cout << value << endl; // 设置输出小数点后面的5位有效数字 cout.precision(5); cout.flags(cout.fixed); //定点法,设置小数点后面输出的位数 cout << value << endl; // 取消定点法 cout.unsetf(cout.fixed); cout << value << endl; system("pause"); return 0; }
输出结果