views:

492

answers:

4

Why Oracle is not using Bankers rule (the rounding method)?

+1  A: 

You can always implement your own function for banker's rounding as described here.

0xA3
+1  A: 

Banker's rounding round's 0.5 to 0: it round's towards even numbers.

Eamon Nerbonne
Oops, I put in the "explanation" of rounding 0.5 to 1. The OP did not mention it. Fixed now.
Thilo
+7  A: 

Accurate decimal arithmatic is a large and complex subject.

Google 'mike colishaw decimal rounding' if you want to read the ahem Oracle on the subject.

Basically there are many rounding schemes which are possible:-

Round everthing down - the default in most languages including C as Oracle is written in C this is probably why they do this.

Round everything up - rarely seen but occasionally needs to be implemented because of obscure market and tax rules.

Basic Half Rounding - anything above .5 rounds up everything else rounds down.

Generous Half Rounding - anything below .5 rounds down everthing else rounds up.

Bankers Rounding - Even numbers follow the Basic Half Rounding rule, odd numbers the Generous Half Rounding rule. This is rarely seen in actual banks which prefer rounding up if the moneys coming thier way and rounding down when its going the clients way.

ORACLE NUMBER is actually a pretty good Decimal Arithmatic implementation and is accurate as far as it goes.

James Anderson
+1 for Oracle pun!
Adam Hawkes
+3  A: 

Oracle has implemented round half away from zero:

SQL> select round(22.5) from dual
  2  /

ROUND(22.5)
-----------
         23

SQL> select round(23.5) from dual
  2  /

ROUND(23.5)
-----------
         24

SQL> select round(-23.5) from dual
  2  /

ROUND(-23.5)
------------
         -24

SQL> select round(-22.5) from dual
  2  /

ROUND(-22.5)
------------
         -23

SQL>

Why don't they change it to Bankers' Rounding? Well, for most purposes round half away from zero is good enough. Plus there's that old fallback, changing it would likely break too much of the existing codebase - Oracle's own as well as all their customers.

APC