BigDecimal rounding fun

Discussion in 'Java' started by laredotornado, Nov 18, 2010.

  1. Hi,

    I'm using Java 1.6. BigDecimal division seems to be rounding to the
    tenths decimal place and I would prefer it round to the hundredths
    decimal place. I have

    final BigDecimal avgRate = sum.divide(totalDays,
    BigDecimal.ROUND_HALF_EVEN);

    If totalDays is 6, and sum is 634, the result above is giving me
    105.7, but ideally, I would want 105.67 (since the result is
    105.666667). Any ideas how to adjust the division above to get the
    result I want?

    Thanks, - Dave
     
    laredotornado, Nov 18, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    65
    Views:
    1,813
    Mabden
    May 18, 2004
  2. Replies:
    3
    Views:
    1,270
  3. dolphin
    Replies:
    4
    Views:
    333
    Jorgen Grahn
    Aug 25, 2007
  4. Stanimir Stamenkov
    Replies:
    4
    Views:
    2,635
    Stanimir Stamenkov
    Jul 18, 2008
  5. Samuel Lown

    Unexpected BigDecimal rounding issue

    Samuel Lown, May 6, 2009, in forum: Ruby
    Replies:
    5
    Views:
    202
    Robert Klemme
    May 6, 2009
Loading...

Share This Page