Subject RE: [firebird-support] Bankers Rounding
Author Svein Erling Tysvær
You could try something like

select case
(cast(MyField as Integer)/2)*2 <> cast(MyField as Integer) //Does Firebird round to odd number?
and cast(MyField * 2 as Integer) = MyField * 2 //And is it exactly 0.5?
when MyField > 0
then cast(MyField - 0.1 as Integer) //Round down positive numbers
else cast(MyField + 0.1 as Integer) //Round up negative numbers
else cast(MyField as Integer) //Just let Firebird round as usual
from MyTable

This should round down 2.45, 2.5 and 3.45, but round up 2.55, 3.5 and 3.55. Though don't expect this to work with real numbers (as opposed to decimal numbers).

And a little disclaimer: The algorithm above isn't taken from any book or program, it just popped up in my fragile, error-prone mind when reading Thomas' question. Hence, it should be tested thoroughly before being trusted.


-----Original Message-----
From: [] On Behalf Of Thomas Clarke
Sent: 21. november 2007 14:13
Subject: RE: [firebird-support] Bankers Rounding

Apologies the Firebird version is 2.0.3.



Hello to everyone,

I have the following challenge:

I am manipulating data extracted from an Informix 10 database using Java,
JayBird and Firebird 2.1. The output file is going to be imported into an
ACCPAC accounting application. The challenge I face is that ACCPAC expects
the numbers to be rounded using Bankers Rounding
Does anyone know of a UDF or a technique that can provide this type of
rounding in Firebird?


Thomas Clarke.