That appears to be it Dina. Thanks a ton.

-----Original Message-----
From: Dina Hess [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 07, 2006 1:37 PM
To: CF-Talk
Subject: Re: Java help

Bobby,

I think this is what you want:


import java.math.*;
import java.text.*;
import java.util.Locale;

public class BigDecimalFormatTest {

 public static void main (String[] args) {
  double [] nums = {71.715,71.725,71.735,71.745,71.755,71.765,71.775,71.785,
71.795};
  NumberFormat form;
  form = NumberFormat.getCurrencyInstance(Locale.US);
  for (int i = 0; i < nums.length; ++i) {
   BigDecimal theNumber = new BigDecimal (Double.toString(nums[i]));
   theNumber = theNumber.setScale(2, RoundingMode.HALF_UP);
   System.out.println(form.format(theNumber));
  }

 }
}

The key here is the double conversion to BigDecimal and setting the rounding
mode to half_up. The reason you weren't getting what you thought you should
is because DecimalFormat uses the half_even rounding mode.

Dina



On 10/7/06, Bobby Hartsfield <[EMAIL PROTECTED]> wrote:
>
> Thanks for the suggestion. I saw that link before but dismissed it for
> some
> reason. I guess I assumed it was doing something else. In any event, I
> just
> tried it and it DID come up with different output but still not what it
> should be. I may very well be using it wrong though. It's probably obvious
> that I'm no Java programmer. I'm basically just taking what I know about
> programming in general and the syntax of JavaScript and doing the best I
> can
> here.
>
> This is what I have from your suggestion and what it displays.
>
> import java.text.*;
> import java.math.BigDecimal;
>
> public class dollarFormattingTest
> {
> public static void main(String[] args)
> {
> DecimalFormat dollarFormat = new DecimalFormat("$0.00");
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.815)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.825)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.835)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.845)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.855)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.865)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.875)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.885)));
> System.out.println(dollarFormat.format(new java.math.BigDecimal(71.895)));
> }
> }
>
>
> This is the output now...
>
> $71.81
> $71.83
> $71.83
> $71.84
> $71.86
> $71.86
> $71.88
> $71.89
> $71.89
>
> That's either extremely weird... or I'm completely missing something
> obvious. :-/
>
>
> -----Original Message-----
> From: Denny Valliant [mailto:[EMAIL PROTECTED]
> Sent: Saturday, October 07, 2006 1:25 AM
> To: CF-Talk
> Subject: Re: Java help
>
> Could this be it?
>
> http://forum.java.sun.com/thread.jspa?threadID=736383&messageID=4230346
>
>
> On 10/6/06, Bobby Hartsfield <[EMAIL PROTECTED]> wrote:
> > I should also mention that I tried this as well...
> .....
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.407 / Virus Database: 268.13.0/465 - Release Date: 10/6/2006
>
>
>
>
> 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:255905
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to