用std::cout.precision() 和 std::cout.setf() 函数
double num = 1234567.1234567; std::cout << num << " "; std::cout.setf(std::ios::fixed, std::ios::floatfield); std::cout << num << " "; std::cout.precision(4); std::cout << num << " ";
结果:
1.23457e+06 1234567.123457 1234567.1235