cout << double

This is a discussion on cout << double within the C++ Programming forums, part of the General Programming Boards category; Hi, When I use cout to print a double it only shows the first few digits of the mantissa. Why ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    32

    cout << double

    Hi,

    When I use cout to print a double it only shows the first few digits of the mantissa. Why is that? How could I make it print the whole thing?

    Seron

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Use the setprecision modifier.
    Code:
    double foo = 1.123456
    cout << setprecision(3) << foo << endl;
    cout << setprecision(7) << foo << endl;
    Output:
    1.12
    1.123456

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    aaaha,
    Thanks man!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM
  4. Compiles but won't cout?
    By Kayoss in forum C++ Programming
    Replies: 2
    Last Post: 05-15-2006, 01:27 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM

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