我是C++的新手,正在爲一段代碼掙扎。我在對話框中有一個靜態文本,我想在點擊按鈕時進行更新。將雙精度值格式化爲小數點後1位
double num = 4.7;
std::string str = (boost::lexical_cast<std::string>(num));
test.SetWindowTextA(str.c_str());
//test is the Static text variable
但是文本顯示爲4.70000000000002。我如何讓它看起來像4.7。
我使用.c_str()
,否則會出現cannot convert parameter 1 from 'std::string' to 'LPCTSTR'
錯誤。
可能重複[?如何「COUT」正確的號碼double值的小數位(http://stackoverflow.com/questions/4217510/how -to-cout-the-correct-number-of-decimal-places-of-double-value) – Dariusz
這與'.c_str()'無關! – Dariusz