× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I run your code with double a = 5.345, b = 1.145, c = 2.645;

and the results:

was: 5.345 ,now: 5.34
was: 1.145 ,now: 1.15
was: 2.645 ,now: 2.65

So 5.345 was still not rounded right.  Why?

Wayne
-----Original Message-----
From: BMIROW@aol.com [mailto:BMIROW@aol.com]
Sent: Thursday, December 20, 2001 12:14 PM
To: java400-l@midrange.com
Subject: RE: DecimalFormat


This worked for me.  Is a little bit of a run around.

import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.math.*;

public class Test {


//--------------------------------------------------
    public static void main(String args[]){
        new Test();
        System.exit(0);
    }

//--------------------------------------------------
    public Test() {
       double a = 1.244;
       double b = 1.245;
       double c = 1.246;

       try {
         BigDecimal bd = new BigDecimal(a);
         BigDecimal bd1 = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
         dsp("was: " + a + " ,now: " + bd1.toString());
         bd = new BigDecimal(b);
         bd1 = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
         dsp("was: " + b + " ,now: " + bd1.toString());
         bd = new BigDecimal(c);
         bd1 = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
         dsp("was: " + c + " ,now: " + bd1.toString());
         }
       catch(Exception e) { e.printStackTrace(); }
    }



//--------------------------------------------------
  private void dsp(String s) { System.out.println(s); }

}


_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.