setting and resetting stream precision

Discussion in 'C++' started by john smith, Aug 5, 2003.

  1. john smith

    john smith Guest

    Hi, I would like to save a stream's output precision and then change the
    precision and then restore it. One example I found was using
    ios_base::fixed, and ios_base::floatfield. But on my machine this only
    gives 6 or 8 digits after the decimal. I would like at least 12. If I do
    cout.precision(12), then cout is forever set to 12 precisions from that
    point on. I guess I can call cout.precision(4) when I'm done, but how do I
    know that 4 is the default?

    example:
    ios_base::fmtflags f = cout.flags();
    cout.setf(ios_base::fixed, ios_base::floatfield);
    cout << 12.5123123123123123123123123123 << endl;
    cout.flags(f);
    cout << 12.5123123123123123123123123123 << endl;

    Thanks in advance.
     
    john smith, Aug 5, 2003
    #1
    1. Advertising

  2. john smith

    tom_usenet Guest

    On Tue, 5 Aug 2003 11:33:14 -0400, "john smith" <>
    wrote:

    >Hi, I would like to save a stream's output precision and then change the
    >precision and then restore it. One example I found was using
    >ios_base::fixed, and ios_base::floatfield. But on my machine this only
    >gives 6 or 8 digits after the decimal. I would like at least 12. If I do
    >cout.precision(12), then cout is forever set to 12 precisions from that
    >point on. I guess I can call cout.precision(4) when I'm done, but how do I
    >know that 4 is the default?
    >
    >example:
    >ios_base::fmtflags f = cout.flags();
    >cout.setf(ios_base::fixed, ios_base::floatfield);
    >cout << 12.5123123123123123123123123123 << endl;
    >cout.flags(f);
    >cout << 12.5123123123123123123123123123 << endl;


    http://www.boost.org/libs/io/doc/ios_state.html

    Tom
     
    tom_usenet, Aug 5, 2003
    #2
    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. Thomas Chassaing

    Setting the default precision in mxNumber

    Thomas Chassaing, Jun 4, 2004, in forum: Python
    Replies:
    1
    Views:
    280
    Scott David Daniels
    Jun 4, 2004
  2. big-red

    setting precision with C++

    big-red, Sep 30, 2006, in forum: C Programming
    Replies:
    2
    Views:
    1,727
    big-red
    Oct 3, 2006
  3. John Friedland
    Replies:
    0
    Views:
    356
    John Friedland
    Jul 21, 2006
  4. dolphin
    Replies:
    6
    Views:
    581
    Thomas Fritsch
    Mar 18, 2007
  5. Kay Y. Jheallee

    Setting longer default decimal precision

    Kay Y. Jheallee, Nov 18, 2013, in forum: Python
    Replies:
    7
    Views:
    130
    Tim Golden
    Nov 20, 2013
Loading...

Share This Page