CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2001
    Posts
    488

    Conversion from float to CString

    Does anyone know a good conversion from float to CString, or from float to char?


  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: Conversion from float to CString


    float x = 1.23f;
    CString str;
    str.Format("%f",x);







  3. #3
    Join Date
    May 2001
    Location
    Madrid-Spain
    Posts
    1,123

    Re: Conversion from float to CString

    float num = 3.5;
    char c = 'e';
    CString string;
    string.Format ("%f", num);
    string.Format ("%c", c);

    I am Miss Maiden... Miss Iron Maiden :-D

  4. #4
    Join Date
    Mar 2001
    Posts
    143

    Re: Conversion from float to CString

    Use .Format for CString or sprintf for char pointer.

    ex:

    CString csStr;
    csStr.Format("%f", 3.14)
    // ...
    char *lpszStr = (char*)malloc(sizeof(char) * 4);
    sprintf(lpszStr, "%f", 3.14);





  5. #5
    Join Date
    Oct 2000
    Location
    Ottawa, CANADA. (CNADA ROCKS!!)
    Posts
    1,895

    Re: Conversion from float to CString

    float float = 1.0003;
    CString temp;
    tmp.Format ("%f", float);

    Rate this post if helped.
    and Canada rocks!! Peace bro.

  6. #6
    Join Date
    Apr 2001
    Posts
    488

    Re: Conversion from float to CString

    Thanks, that was very useful


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured