help with iomanip

This is a discussion on help with iomanip within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to use setprecision to output at most 5 digits after the decimal point of a floating ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    38

    help with iomanip

    Hi,

    I am trying to use setprecision to output at most 5 digits after the decimal point of a floating point number. The problem is that it prints out more than 5 digits if there are zeros. For example, if I have a number

    0.0456784523

    I would like to print out
    0.04567

    But instead it prints out 0.045678
    So it doesnt count the 0 as a digit.
    Can somebody tell me how to do this?
    Thanks
    Mark

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Try
    Code:
      double d=0.0456784523;
      cout << fixed << setprecision(5) << d;
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iomanip
    By ZerOrDie in forum C++ Programming
    Replies: 7
    Last Post: 09-28-2002, 06:26 AM

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