Eion wrote:
> I have an app which has two Dbase tables in a master/detail scenerio.
> The master has a current balance field of a field in the details table.
> This is occasionally incorrect due to trying to add or subtracting due
> to detail changes.
> I therefore have reconcilation procedure which then goes and
> recalculates the current balance for all master records.
>
> The problem I have is that of the records that are wrong, ie the total
> to the detail records don't equal the master, there are a number which
> show in my list of differences where the values are the same i.e.
> Details total 833.40 and master equals 833.40.
>
> The database fields are numeric with 8 digits and 2 decimals. The show
> as TFloatfields against the database. The variable I am using in the
> procedure to add up to detail values is real so I am confused on why
> this might be. I have tried various ways to get around it such as using
> extended, converting the fields to strings and back again and still they
> show that the two numbers are different.
How big is the difference? .01c or .02c?
If so, that indicates you likely have a rounding issue.
dBase commonly stores numbers as expanded BCD so the BDE will be translating
that into a Float for you and I seem to recall it does have some 'issues' in
that area, although there is a BDEAdmin option to attempt to resolve this.
Also, you may have a rounding issue in the client side with fractions of a
cent (possibly introduced by the BDE) accumulating into a whole cent.
Ideally, you want to round each value appropriately _before_ adding it into
your total. Unfortunately, the rounding routines in Delphi are rather weak -
they all return Longints rather than Extended so you may have some
representational issues for large numbers.
Also, Round performs engineering rounding rather than financial rounding
i.e. -Round(X) <> Round(-X) so if your details include negative numbers,
you'll need to be careful to round consistently.
The Maths.pas has some additional rounding routines, namely Ceil and Floor
but they also return Longints and perform engineering rounding.
Because of all the above, I wrote my own rounding routines in 80x87
assembler since I've long since learned to distrust whatever the compiler or
language libraries provide and I don't like chasing .01c differences through
whole accounting system databases :-)
TTFN,
Paul.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz