double value = 12.3456789; //默认cout输出6位有效数字(最后一位四舍五入) //12.3457 cout << value << endl; //修改cout的输出精度为4 //12.35 cout.precision(4); cout << value << endl; //修改cout精度为小数点后的位数 //12.3457 cout.flags(cout.fixed); //定点法:精度,用来表示小数点后面的位数 cout << value << endl; cout.unsetf(cout.fixed); //取消定点法 cout << value << endl;