Subject Re: [IBO] Rounding problems Rohit Gupta 2001-08-07T21:14:12Z
The problem is that its an idiotic concept to store floating point in
binary - it does not provide an exact representation. That is, for
example 13.47 may not be storable in 64 bits as exactly 13.47 - it
may be stored as 13.46549999999

Assuming that IBO is storing it as BCD - as soon as the amount is
converted to binary or text you have a rounding problem. If you
want perfect resutls you have to use BCD in Delphi, or you have to
continuously round your figures after each sub-calculation. And
then we always cross-check and adjust one of the figures until

For instance we have gst (like your VAT). Work out GST on
GST_Exc figure. Work out Gst_Inc figure from Gst_Exc figure -
things dont match up, so we go back and add/subtract half a cent
to the gst figure so that things will add up permanently in the future.

To: IBObjects@yahoogroups.com
From: "Leeway" <lee@...>
Date sent: Tue, 07 Aug 2001 08:03:15 -0000
Subject: [IBO] Rounding problems

> I need to extract the VAT from a amount.
> I have four fields
> the fields are NUMERIC(18,2)
> EP_VAT (the amount of VAT)
> EP_INCL (the amount including VAT)
> EP_EXCL (the amount without the VAT)
> VAT (the percentage VAT)
>
> The example
> EP_INCL = 766.05
> VAT = 21.00
>
> begin
> //to calculate the amount VAT :
> // amount-including-vat divided by 100+vat% times vat%
> // (766.05 / (100 + 21.00)) * 21.00
> // (766.05 / 121) * 21.00 = 132.9508 this is correct
>
> QTIB_Art.FieldByName('EP_VAT').AsCurrency :=
> ((QTIB_Art.FieldByName('EP_INCL').AsCurrency / (QTIB_Art.FieldByName
> ('VAT').AsCurrency + 100)) * QTIB_Art.FieldByName('VAT').AsCurrency);
>
> //to calculate the amount exclusive VAT :
> // amount-including-vat divided by 100+vat% times 100
> // (766.05 / (100 + 21.00)) * 100
> // (766.05 / 121) * 100 = 633.0991 the fields are
> // numeric(18,2) so it rounds on two decimals and should give
> // 633.10 but it gives 633.09 what am I doing wrong ?
>
> QTIB_Art.FieldByName('EP_EXCL').AsCurrency :=
> ((QTIB_Art.FieldByName('EP_INCL').AsCurrency /(QTIB_Art.FieldByName
> ('VAT').AsCurrency + 100)) * 100);
>
> end
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

Regards

Rohit

======================================================================
CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand
PH (649) 489-2280
FX (649) 489-2290
email rohit@... or r.gupta@...
======================================================================