2011-04-26 41 views
0
*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::stringstream ss; 
ss<<temp/1024; 

我曾與/嘗試沒有設定精度,我還是得到了12.999,而不是12.9990234375 請指教我做了什麼錯?謝謝。 安德魯C++幫助從字符串SETF floatfield

+1

嗯,你在哪裏設置精度?而你想做什麼,你期望'ss'是「12.9990234375」? – 2011-04-26 14:55:38

+1

ss是stringstream。我對ss << std :: setprecision(10)<< temp/1024;有效。再次感謝基洛夫。 – AndrewS 2011-04-26 15:04:09

回答

2

cout

std::cout<< "temp " << std::setprecision(15) << temp <<endl; 

編輯添加std::setprecision(15):對不起,如果我得到你錯了。您希望打印12.9990234375,或者您希望ss12.9990234375?如果第二個,然後使:

ss << std::setprecision(15) << temp/1024; 
+0

是的,cout或stringstream中的setprecision很好地工作。非常感謝。 – AndrewS 2011-04-26 15:02:00

+0

不客氣(: – 2011-04-26 15:02:46