In MFC programs, you can use the Format method to easily convert numeric types such as int, float, and double to CString strings. The following is a format description supported by the CString format:%c single character
%d decimal integer (int)
%ld decimal integer (Long)
%f decimal floating-point number (float)
%LF decimal floating-point number (double)
%o Octal number
%s string
%u unsigned decimal digits
%x Hex Number
1, int conversion to CString CString str;
int number=15;
Str= "15"
Str. Format (_t ("%d"), number);
Str= "15" (preceded by two spaces; 4 indicates that 4 digits will be occupied, and if the number exceeds 4, all numbers will be output and will not be truncated)
Str. Format (_t ("%4d"), number);
Str= "0015" (. 4 indicates that 4 digits will be occupied, and if the number exceeds 4 digits, all numbers will be output and will not be truncated)
Str. Format (_t ("%.4d"), number);
A long conversion to CString is similar to the above, with the need to change%d to%ld.
2, double conversion to CString CString str;
Double num=1.46;
Str= "1.46"
Str. Format (_t ("%LF"), num);
Str= "1.5" (. 1 means to leave 1 digits after the decimal point, rounded by more than 1 digits after the decimal point)
Str. Format (_t ("%.1LF"), num);
Str= "1.4600"
Str. Format (_t ("%.4f"), num);
Str= "1.4600" (preceded by 1 spaces)
Str. Format (_t ("%7.4f"), num);
Float conversion to CString method is similar to the above, the lf% to f% on it.
3.CString converted to double type
CString ss= "123.21";
Double Dd=atof (ss); 4.CString converted to int type
CString str = "123";
int i = _ttoi (str);//Convert to 64-bit int type can use _TTOI64 ()