C++ Help with setf floatfield from string
*mit = 13311
std::istringstream iss(*mit);
double temp;
iss.setf(ios::fixed, ios::floatfield);
iss.precision(15);
iss >> temp;
std::cout<<"temp "<<temp<<endl;
std::stringst开发者_高级运维ream ss;
ss<<temp / 1024;
I had tried with / without set precision, I still got 12.999, instead 12.9990234375 Please advise what did I do wrong? Thanks. Andrew
Add std::setprecision( 15 )
in the cout
std::cout<< "temp " << std::setprecision( 15 ) << temp <<endl;
EDIT: sorry, if I got you wrong. You expect to see 12.9990234375
printed or you expect ss
to be 12.9990234375
? If the second, then make:
ss << std::setprecision(15) << temp / 1024;
精彩评论