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

    How convert a exponent double data to a string?

    Hello
    .
    .
    double i=1.2e21;
    CString j;
    .
    .
    I want j equal "1.2e21",how can I get that?
    Thanks in advance.


    Programe is very interesting!
    Markup

  2. #2
    Join Date
    May 1999
    Posts
    327

    Re: How convert a exponent double data to a string?

    To convert a double to a string, you do

    char str[80];
    double a = 32433.2321;
    sprintf(str, "%f", a);

    The second argument, which in this case is "%f", can be formatted just
    like the printf format.

    Hope this helps.

    Danielle


  3. #3
    Join Date
    May 1999
    Posts
    327

    Re: How convert a exponent double data to a string?


    Also, to copy then to CString format use strcpy so

    strcpy(j, str);


  4. #4
    Join Date
    Apr 1999
    Posts
    15

    Re: How convert a exponent double data to a string?

    Thanks a lot.
    But the length of the string is very short,so when I finish the convertion I want to keep the exponent format in the string.
    like
    .
    double i=2.3e300;
    CString j;//its length is 10 chars.
    .
    In my program j must have the form
    " 2.3e300",how can do that?
    thanks.

    vector

  5. #5
    Join Date
    Apr 1999
    Posts
    15

    I get it.Thanks!

    using sprintf(...,%e,...),I get it.
    Thanks!

    vector

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