CString
-
how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!
Lookup the "Data Conversion" functions in the MSDN library (atof). Basicaly you convert the string to a number add the new value to the old and then use CString::Format() function to replace the string with the new value.
double old = atof(&string); // Get current value
old += new; // Add new value to old value
string.Format(_T("%f"),old); // replace sting with new valueor something simular. INTP
-
how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!
Hi, I create this function to convert from double to CString. var is the number to be converted ndec Number of digits after decimal point
CString do2CStr(double var,int ndec) { int decimal, sign; char *buffer; buffer = _fcvt( var, ndec ,&decimal, &sign ); int len=strlen(buffer); CString number(buffer); CString valor; if(sign)//negative number valor="-"+number.Left(decimal)+"."+number.Right(len-decimal); else valor=number.Left(decimal)+"."+number.Right(len-decimal); return valor; }
Daniel Cespedes "There are 10 types of people, those who understand binary and those who do not" "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org -
Hi, I create this function to convert from double to CString. var is the number to be converted ndec Number of digits after decimal point
CString do2CStr(double var,int ndec) { int decimal, sign; char *buffer; buffer = _fcvt( var, ndec ,&decimal, &sign ); int len=strlen(buffer); CString number(buffer); CString valor; if(sign)//negative number valor="-"+number.Left(decimal)+"."+number.Right(len-decimal); else valor=number.Left(decimal)+"."+number.Right(len-decimal); return valor; }
Daniel Cespedes "There are 10 types of people, those who understand binary and those who do not" "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.orgWhy, doesn't CString::Format work for you ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!