|
Subject:
|
double to string?
|
|
Posted By:
|
chris97b
|
Post Date:
|
9/22/2003 8:19:01 PM
|
I need to output a double to a static control. Is there any way to convert a double to a string? (I know about the SetDlgItemInt function, but I believe that only works for ints. I MUST make the output a double, or some data type that supports decimals) thanks, Chris
|
|
Reply By:
|
xgbnow
|
Reply Date:
|
9/23/2003 8:19:15 AM
|
You can use the MFC CString class to create a string object. One of the class members Format is able to do the conversion for you.
CString s; double x;
x = 23.12345; s.Format("%7.3f", x); // Outputs 23.123 AfxMessageBox(s);
Hope this helps. You can read more about CString in the help file.
Larry Asher
|
|
Reply By:
|
chris97b
|
Reply Date:
|
9/23/2003 1:54:10 PM
|
Excellent, that works great. One more Q though, :) How would I go about getting a double from an edit box also? Thanks
|
|
Reply By:
|
xgbnow
|
Reply Date:
|
9/23/2003 1:58:19 PM
|
Going the other way, I believe you can use the atof() Function. This converts an ascii value to a real.
double x;
x = atof(m_dStringVal);
Hope that works.
Larry Asher
|
|
Reply By:
|
chris97b
|
Reply Date:
|
9/23/2003 2:34:19 PM
|
Actually I found an even easier way. just associate a double with the edit control, and when you call UpdateData, you can then just use the member variable. THanks again for the help on output.
|