Thread: Limiting Decimals

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    Limiting Decimals

    Hey, Im writing a money type calculations program, how do I limit the output's number of decimals?

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    using printf()'s format specifiers?

    try something like

    printf("Value: %.2f\n",1.2345);

    the .2 specifies the float point precision should be set to 2 digits.

    output: Value: 1.23

    go here for a list and explaination of format specifiers for printf()

    http://www.cplusplus.com/ref/cstdio/printf.html
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    2
    Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help to show decimals
    By engstudent363 in forum C Programming
    Replies: 4
    Last Post: 02-19-2008, 04:13 PM
  2. limiting a plugin function from opening a file
    By Jath in forum C Programming
    Replies: 3
    Last Post: 01-31-2008, 08:05 AM
  3. allow decimals
    By dankassdann in forum C++ Programming
    Replies: 3
    Last Post: 10-28-2006, 06:41 PM
  4. how to show the % sign and remove decimals?
    By seal in forum C Programming
    Replies: 5
    Last Post: 08-31-2005, 05:29 PM
  5. Decimals to Fractions
    By ToasterPas in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 12:58 PM