我是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