CStringと二重変換
Cstring Double Convert Each Other
1.doubleをCStringに変換
http://www.sowsoy.com/topics-410.html
C ++からCStringメソッドへのDoulbe / float / int
MFCプログラムでは、Formatメソッドを使用して、int、float、doubleなどの数値型をCString文字列に簡単に変換できます。以下は、CStringのフォーマットでサポートされているフォーマットの説明です。
%c single character %d decimal integer (int) %ld decimal integer (long) %f decimal floating point number (float) %lf decimal floating point (double) %o octal number %s string %u unsigned decimal number %x hexadecimal number
1、intはCStringに変換されます
CString str int number=15 //str='15' str.Format(_T('%d'),number) //str=' 15' (there are two spaces in front 4 means that it will occupy 4 digits. If the number exceeds 4 digits, all digits will be output and will not be truncated) str.Format(_T('%4d'),number) //str='0015' (.4 means it will occupy 4 digits. If the number exceeds 4 digits, all digits will be output and will not be truncated) str.Format(_T('%.4d'),number) The method of converting long to CString is similar to the above, just change %d to %ld.
2、CStringに二重変換
CString str double num=1.46 //str='1.46' str.Format(_T('%lf'),num) //str='1.5' (.1 means 1 bit after the decimal point, more than 1 after the decimal point is rounded off) str.Format(_T('%.1lf'),num) //str='1.4600' str.Format(_T('%.4f'),num) //str=' 1.4600' (1 space in front) str.Format(_T('%7.4f'),num) The method of converting float to CString is similar to the above, and changing lf% to f% is fine.
3.10進数を8進数に変換します
CString str int num=255 //str='377' str.Format(_T('%o'),num) //str='00000377' str.Format(_T('%.8o'),num)
2.CStringはdoubleに変換されます
atof()