Thread: Printing specified number of decimal places?

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    135

    Printing specified number of decimal places?

    Let's say an integer is used to specify the number of decimal places an output is displayed, how would I implement this integer into the floating point output format?

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Hmm. I would look into the documentation for printf.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    135
    One of my friends mentioned something like separating the printf components %. and f while inserting the variable in between. I have no idea how it is done.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Still the same question - why haven't you read the printf manual page to find out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    135
    Ah, I got it! Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why aren't my answers having decimal places
    By curls8 in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2010, 01:45 AM
  2. %g doesn't print as many decimal places as %f
    By octoc in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 12:16 PM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. how to set decimal places Borland C++ 3.0 compiler???
    By neo_phyte in forum C++ Programming
    Replies: 10
    Last Post: 08-31-2006, 05:08 PM