My guess would be that neither is "wrong", but just using different rounding
methods. If you are concerned about both returning different results, you
could add (or subtract, based on sign) .0001 before doing the ROUND.
SELECT ROUND(mynum + SIGN(mynum)*0.0001) FROM DUAL;
Of course, this may not work %100 if you store more than three decimal
places, e.g. "-.8749".
Just a thought. HTH! GL! :)
Rich Jesse System/Database Administrator
[EMAIL PROTECTED] Quad/Tech International, Sussex, WI USA
> -----Original Message-----
> From: Bill Buchan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 28, 2002 10:59 AM
> To: Multiple recipients of list ORACLE-L
> Subject: Slightly OT: Rounding Negative Numbers
>
>
>
> I'm trying to consolidate some numbers generated by a PL/SQL
> report vs. a
> Java based report and these seem to be out due to rounding errors on
> negative numbers.
>
> In PL/SQL if I for example, round to 2 decimal places:
>
> SQL> select round(-0.875,2) from dual;
>
> ROUND(-0.875,2)
> ---------------
> -.88
>
>
> In Java:
>
>
> import java.*;
>
> public class Round {
>
> public static void main(String[] args) {
> double a = -0.875;
> int i = (int)java.lang.Math.round(a*100);
> double z = i;
> z = z / 100;
> System.out.println(z);
> }
> }
>
> >java Round
> -0.87
>
>
> which is 0.01 different (1 pence in this case). If I use
> positive numbers
> (+0.875) when the answer is 0.88 for both PL/SQL and Java.
> PL/SQL's answer
> looks "more"correct to me for the negative value - but what is the
> mathematically correct rounding of -0.875?!
>
> Thanks!
>
> - Bill.
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Jesse, Rich
INET: [EMAIL PROTECTED]
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
San Diego, California -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).