Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Double to CString Conversion

343 views
Skip to first unread message

Jason Craig

unread,
Nov 27, 2001, 2:08:58 AM11/27/01
to
I'm working on a small project in order to learn MFC. I want to
convert a double to a CString to place in an edit box. I've tried to
cast the double to CString with no luck. I tried to convert the
double to a string and then cast it to a CString with no luck.
Am I missing an easy fix to this?

If you have a solution for me please let me know
at:jasc...@hotmail.com

Thanks,
Jason

Ajay Kalra

unread,
Nov 27, 2001, 3:30:26 AM11/27/01
to
Use CString::Format:

From MSDN:

CString str;
str.Format(_T("Floating point: %.2f\n"), 12345.12345);

--
Ajay Kalra [MVP - VC++]
ajay...@yahoo.com

Note: Please post all replies to newsgroup only.

"Jason Craig" <jasc...@hotmail.com> wrote in message
news:f310a7ab.01112...@posting.google.com...

Daniel Bevan

unread,
Nov 27, 2001, 3:31:45 AM11/27/01
to
The only data type that can be directly converted to a CString are the
string pointers char *, LPSTR, LPTSTR , etc.

The function you are looking for is CString::Format(..).
It is equivalent to the printf(...) function taking the output format and
list of arguments, writing the fromatted string to the CString object.

A simple example:

CString str;
double num;

num = 65.0;
str.Format("The value is: %f", num);
MessageBox(NULL, str, "",0);

The %f will be replaced by the string representation of your double.

See the documentation for CString::Format(...) and
printf(...) for full details of how to use the string formating functions.

also see sprintf(..) for writing to a string buffer.

Daniel Bevan

"Jason Craig" <jasc...@hotmail.com> wrote in message
news:f310a7ab.01112...@posting.google.com...

0 new messages