Thread: Rounding to the nearest dollar

  1. #1
    Registered User
    Join Date
    Nov 2009

    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
    Check out the floor and ceil methods.



  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    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, 10: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