Subject Rounding problems Leeway 2001-08-07T08:03:15Z
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