and the string conversion double (precision)

1 std: to_string () method is only accurate to six decimal places

double d = 3.1415926535897932384;
std::string str = std::to_string(d);
std::cout << str << std::endl; // 3.141593

2 using stringstream, using setprecision accuracy in the input stream is provided

 std::stringstream ss;
 ss << std::setprecision(15) << d;
 str = ss.str();  // 3.14159265358979
 std::cout << str << std::endl; //3.14159265358979

3 using the number function QString

QString QString::number(double n, char format = 'g', int precision = 6)

 

 

Guess you like

Origin www.cnblogs.com/LuckCoder/p/11947104.html