CString str1,str2,str3,str4;
double dstr1,dstr2,dstr3,dstr3;
GetDlgItemText(IDC_thismonth_water,str1);
GetDlgItemText(IDC_precedingmonth_water,str2);
GetDlgItemText(IDC_fee_water,str3);
str1.Format(
str1怎么样变成double型的

解决方案 »

  1.   

    还就是反过来,怎么把double型转为CString变量
      

  2.   

    double转cstringstr1.format("%f",dstr1);string转double
    dstr1 =(double)atof(str1);
      

  3.   


    str1.Format("%f",dstr1); 
    有报错
    d:\zmh\c++\workspace\fee\fee\newinfo.cpp(97) : error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
            with
            [
                BaseType=wchar_t,
                StringTraits=StrTraitMFC_DLL<wchar_t>
            ]
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      

  4.   

    using the standard printf:sprintf(buff, format, data...)e.g.sprintf(buff, "%lf", 30.9998);
      

  5.   

    严重同意楼上.
    double到cstring :
    int sprintf( char *buffer, const char *format [,argument] ... );cstring到double:
    double atof(const char *string);
      

  6.   

    VS2005下默认为unicode类型,
    double转cstring 
    str1.format("%f",dstr1);  ==>str1.Format(_T("%f"),dstr1);
    string转double 
    dstr1 =(double)atof(str1);==> dstr1 =(double)_wtof(str1)
      

  7.   

    double d = atof(str);
      

  8.   

    你的是在UNicode下吗?要是的话
    用_ttof函数,用法一样