Setting decimal precision in fstream

This is a discussion on Setting decimal precision in fstream within the C++ Programming forums, part of the General Programming Boards category; How do you increase it from six decimal places? A programmer's reference book I have speaks of a precision(int p); ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907

    Setting decimal precision in fstream

    How do you increase it from six decimal places? A programmer's reference book I have speaks of a precision(int p); function, but MSVC++6 doesn't seem to support it.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
      double d = 11.12345678901;
      std::cout.setf(std::ios::showpoint | std::ios::fixed);
      std::cout <<std::setprecision(11) <<d <<std::endl;
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Setting Precision Confusion
    By dnguyen1022 in forum C++ Programming
    Replies: 11
    Last Post: 01-14-2009, 09:38 AM
  2. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  3. Setting precision?
    By markucd in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2006, 04:53 AM
  4. How to set decimal precision...
    By Captain Penguin in forum C++ Programming
    Replies: 5
    Last Post: 10-14-2002, 11:01 AM
  5. setting a float to 4 digit decimal precision
    By river-wind in forum C Programming
    Replies: 8
    Last Post: 01-21-2002, 04:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21