• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rounding to .5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rounding to .5


  • Subject: Re: rounding to .5
  • From: Arturo PĂ©rez <email@hidden>
  • Date: Thu, 7 Jul 2005 20:52:44 -0400

Hi Robert,

I thought that when one used setScale it did not modify the BigDecimal. In that case, to get a truly truncated value one needed to
myVal = new BigDecimal(myVal.setScale(2, BigDecimal.ROUND_HALF_DOWN));


Or did I misunderstand the javadoc?

-arturo

On Jul 6, 2005, at 12:42 PM, Robert Walker wrote:

Glad you found a solution that works for you. However, for precise handling of rounding you should also get familiar with the java.math.BigDecimal class. This class has features for setting the scale using a specified rounding mode. Plus it includes methods for perform math on objects rather than primitives.

Examples:

    BigDecimal myVal = new BigDecimal(25.125);
    myVal.setScale(2, BigDecimal.ROUND_HALF_UP);

This would result in myVal having the value 25.13


BigDecimal myVal = new BigDecimal(25.125); myVal.setScale(2, BigDecimal.ROUND_HALF_DOWN);

This would result in myVal having the value 25.12

On Jul 5, 2005, at 8:13 AM, Dev WO wrote:

Mmmm, let's say thank you Christian, this works like a charm;)
my java knowledge is improving everyday, but I started from the very beginning;)


Thanks again.

Xavier





On Tue, 5 Jul 2005, Christian Brunschen wrote:



 double rounded = Math.round(2.0 * original) / 2.0;



... that should have been

  double rounded = Math.rint(2.0 * original) / 2.0;
                        ^^^^

My apologies,

// Christian




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ WebObjects-dev mailing list email@hidden http://www.omnigroup.com/mailman/listinfo/webobjects-dev


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >rounding to .5 (From: Dev WO <email@hidden>)
 >Re: rounding to .5 (From: Christian Brunschen <email@hidden>)
 >Re: rounding to .5 (From: Christian Brunschen <email@hidden>)
 >Re: rounding to .5 (From: Dev WO <email@hidden>)
 >Re: rounding to .5 (From: Robert Walker <email@hidden>)

  • Prev by Date: WebObjects AJAX Developer/Firm Wanted
  • Next by Date: Correct character sets settings with mysql 4.1.10?
  • Previous by thread: Re: rounding to .5
  • Next by thread: WO 5.2.4 and xCode 2.1?
  • Index(es):
    • Date
    • Thread