streams and floaters

Discussion in 'C++' started by Noah Roberts, Aug 29, 2006.

  1. Noah Roberts

    Noah Roberts Guest

    I have a double that contains the value 1000000. I want to print
    "1000000". Just doing this:

    str << doub;

    results in "1e+006". Attempting this:

    str << std::fixed << doub;

    results in "1000000.000000"

    str << std::fixed << std::noshowpoint << doub

    results in the same.

    >From what I am reading, the last should be exactly what I want but it

    isn't resulting in what I want. What is the correct way?
    Noah Roberts, Aug 29, 2006
    #1
    1. Advertising

  2. Noah Roberts

    BRG Guest

    Noah Roberts wrote:
    > I have a double that contains the value 1000000. I want to print
    > "1000000". Just doing this:
    >
    > str << doub;
    >
    > results in "1e+006". Attempting this:
    >
    > str << std::fixed << doub;
    >
    > results in "1000000.000000"
    >
    > str << std::fixed << std::noshowpoint << doub
    >
    > results in the same.
    >
    >>From what I am reading, the last should be exactly what I want but it

    > isn't resulting in what I want. What is the correct way?
    >


    str << std::fixed << std::noshowpoint << std::setprecision(0) << doub

    should work.

    Brian Gladman
    BRG, Aug 29, 2006
    #2
    1. Advertising

  3. Noah Roberts

    Noah Roberts Guest

    BRG wrote:
    > Noah Roberts wrote:
    > > I have a double that contains the value 1000000. I want to print
    > > "1000000". Just doing this:
    > >
    > > str << doub;
    > >
    > > results in "1e+006". Attempting this:
    > >
    > > str << std::fixed << doub;
    > >
    > > results in "1000000.000000"
    > >
    > > str << std::fixed << std::noshowpoint << doub
    > >
    > > results in the same.
    > >
    > >>From what I am reading, the last should be exactly what I want but it

    > > isn't resulting in what I want. What is the correct way?
    > >

    >
    > str << std::fixed << std::noshowpoint << std::setprecision(0) << doub


    Doesn't setprecision(0) also shut off after the decimal if I have a
    value that needs it?
    Noah Roberts, Aug 29, 2006
    #3
  4. Noah Roberts

    BRG Guest

    Noah Roberts wrote:
    > BRG wrote:
    >> Noah Roberts wrote:
    >>> I have a double that contains the value 1000000. I want to print
    >>> "1000000". Just doing this:
    >>>
    >>> str << doub;
    >>>
    >>> results in "1e+006". Attempting this:
    >>>
    >>> str << std::fixed << doub;
    >>>
    >>> results in "1000000.000000"
    >>>
    >>> str << std::fixed << std::noshowpoint << doub
    >>>
    >>> results in the same.
    >>>
    >>> >From what I am reading, the last should be exactly what I want but it
    >>> isn't resulting in what I want. What is the correct way?
    >>>

    >> str << std::fixed << std::noshowpoint << std::setprecision(0) << doub

    >
    > Doesn't setprecision(0) also shut off after the decimal if I have a
    > value that needs it?


    Yes.

    If this matters to you you will need to test if your number is an
    integer and set the argument to setprecision accordingly. Something like:

    str << std::fixed << std::noshowpoint
    << std::setprecision(x == std::floor(x) ? 0 : 5) << x;

    Brian Gladman
    BRG, Aug 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pawel Banys
    Replies:
    1
    Views:
    493
    Joe Smith
    Jul 8, 2004
  2. =?Utf-8?B?Sm9obiBIb3BwZXI=?=

    streams and querystrings

    =?Utf-8?B?Sm9obiBIb3BwZXI=?=, Jan 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    413
    =?Utf-8?B?Sm9obiBIb3BwZXI=?=
    Jan 21, 2005
  3. =?Utf-8?B?cm9iIGx5bmNo?=

    Problems with image types and response streams....

    =?Utf-8?B?cm9iIGx5bmNo?=, Dec 21, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    308
    =?Utf-8?B?cm9iIGx5bmNo?=
    Dec 21, 2005
  4. Ike
    Replies:
    1
    Views:
    1,950
  5. Fly Cooter

    Re: Clearing floaters in Mozilla

    Fly Cooter, Aug 20, 2005, in forum: HTML
    Replies:
    4
    Views:
    367
    Shawn K. Quinn
    Aug 20, 2005
Loading...

Share This Page