Rounding to the nearest dollar

This is a discussion on Rounding to the nearest dollar within the C++ Programming forums, part of the General Programming Boards category; How do you round up or down a double(not an int) to the nearest dollar? Ex. $23.45 = $23 or ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Rounding to the nearest dollar

    How do you round up or down a double(not an int) to the nearest dollar? Ex. $23.45 = $23 or $25.54 = $26...etc

  2. #2
    Allways learning cs_student's Avatar
    Join Date
    Aug 2008
    Location
    ~/
    Posts
    39
    Check out the floor and ceil methods.

    Regards,


    cs_student

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Easy. Just write a Round() function.
    You know how to round numbers in your head don't you? Just write that out in code with if statements...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange decimal rounding
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 06-12-2008, 01:05 AM
  2. Replies: 4
    Last Post: 10-16-2006, 12:04 PM
  3. Rounding a float to the nearest half
    By kzar in forum C Programming
    Replies: 4
    Last Post: 04-01-2005, 09:07 PM
  4. Help with rounding a number
    By nickk in forum C Programming
    Replies: 3
    Last Post: 06-02-2004, 11:44 AM
  5. rounding to nearest penny
    By sizzle_chest in forum C++ Programming
    Replies: 6
    Last Post: 09-06-2001, 03:57 PM

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