Results 1 to 3 of 3

Thread: Rounding

  1. #1
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default Rounding

    So I this isn't specific to coding, but I want to know of a clever way to round a number in a specific manner.

    So say I have the following number:

    59,323.00

    I want to take that number and round up to the next hundred.

    For example, the number should be:

    59,400.00

    Regardless of what that number should actually round to, I want to always take it and round it up to the next hundred....

    A few more examples:

    983,930.00 --> 984,000.00
    324,802.00 --> 324,900.00
    500.00 --> 500.00 (this is the only exception)

    Can anyone think of a clever way to do this?

    Thanks in advance

  2. #2
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    I was thinking:

    Take your number:

    59,343.00 / 100

    = 593.43 - use Math.rounding, round UP

    = 594.00 * 100

    = 59,400.00

    as long as 59,343 mod 100 does not = 0, i should round up

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You can keep it integral.
    If (number % 100) > 0 then add 100 to number - (number % 100).

Similar Threads

  1. rounding double to two decimal places
    By javaMike in forum Advanced Java
    Replies: 15
    Last Post: 03-10-2010, 12:04 AM
  2. [SOLVED] Rounding off numbers
    By Manfizy in forum New To Java
    Replies: 4
    Last Post: 02-07-2009, 12:44 AM
  3. rounding a double in a number of significant numbers
    By rikribbers in forum Advanced Java
    Replies: 2
    Last Post: 10-27-2008, 03:35 PM
  4. Need help rounding. =/
    By yo1mcool in forum New To Java
    Replies: 1
    Last Post: 10-07-2008, 05:02 AM
  5. Help with java Rounding
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •