Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ MFC double to CString

Sorry for my English.

I need to convert double value to CString, because i need to do AfxMessageBox(double_value);

I find this:

std::ostringstream ost;
ost << double_value;
std::cout << "As string: " << ost.str() << std::endl;
//AfxMessageBox(ost.str()); - Does not work.

How i can do this?

like image 576
user2254511 Avatar asked Nov 15 '25 09:11

user2254511


1 Answers

AfxMessageBox expects a CString object, so format the double into a CString and pass that:

CString str;
str.Format("As string: %g", double);
AfxMessageBox(str);

Edit: If you want the value displayed as an integer (no value after decimal point) then use this instead:

str.Format("As string: %d", (int)double);
like image 116
trojanfoe Avatar answered Nov 17 '25 10:11

trojanfoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!