CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Apr 2008
    Posts
    8

    Question exponent to decimal conversion fn()

    Hi,
    I have the following program:

    int main()
    {
    float fVar = 1e+11;

    printf("%.10f", fVar);
    return (0);
    }

    When I print fVar, the output is 99999997952.0000000000

    This is understandably because the value 1e+11 is too large to be stored in fVar so it got truncated before getting assigned to fVar.

    But nevertheless if I print it with scientific notation it's prints fine as 1e+11

    Scientific notation:
    ---------------------------
    cout<<setiosflags(ios::scientific) << floatVar<<endl;


    Now I want that I should be able to print 1e+11 as 100000000000 (i.e. 1 follwed by 11 zeros).

    Is there some way I can print the output from fVar as 100000000000?
    Is there some library function that I can use to convert the exponent (1e+11) to decimal and then print it?

    PS: If you don't mind hopping to another Forum related to same discussion, please check out
    http://forums.devx.com/showthread.php?t=167270

    Regards
    Last edited by codekomlete; April 5th, 2008 at 12:18 PM.

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