【MFC】MFC文本框中显示浮点数

CString strNumber;
strNumber.Format("%0.2f",tim.getTimeMilli());
SetDlgItemText(IDC_TIME_USED,strNumber);

 error C2664: 'voidATL::CStringT::Format(const wchar_t *,...)' : cannot convertparameter 1 from 'const char [6]' to 'const wchar_t *'
 with
1>         [
1>            BaseType=wchar_t,
1>            StringTraits=StrTraitMFC_DLL
1>         ]
1>         Types pointed to areunrelated; conversion requires reinterpret_cast, C-style cast orfunction-style cast

解决方法:
采用了UNICODE编码, 
可以用 
a.Format(L "%d ",  b); 
或者 
a.Format(_T( "%d "),   b);
即:strNumber.Format(_T("%.2f "), tim.getTimeMilli());
OK!

原文地址:https://www.cnblogs.com/eaglediao/p/7136498.html