I know how to convert a CString to an integer, but that won't fly here ... I am making a Win32 app that makes calculations and displays the results in EditBoxes based on values in other EditBoxes. So now that I have extracted the CStrings from the EditBoxes, I need to convert this to decimal. (not long or integer). I might end up having to convert a value like "32.141579" into 32.141579 NOT 32, as what would happen if I used CString to Integer code ... Please help; this is an MFC dialog based app being built with Visual C++ 6.0 Standard Edition. It is designd to run on a Win32/Win9x/WinXP environment ... Thank You ...
How do you convert a CString to a decimal value in C++?
I dont know if I quite understand you question, but try this example:
CString s, t, u;
s = "1.2345";
t = "5.4321";
float x, y, z;
char c[10];
x = atof(s); //convert CString to float
y = atof(t); //dito
z = x + y; //add the floats
gcvt(z,6,c); //convert float to char string
u = c; //copy char string to CString
MessageBox(u);//display results
Reply:If I remember correctly, you should be able to typecast the result.
Example:
double num = (double) Editbox1.value + Editbox2.value
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment