[fpc-pascal] Freepascal Floating Point Issue

Bernd Oppolzer bernd.oppolzer at t-online.de
Thu Aug 24 23:29:42 CEST 2017


Am 24.08.2017 um 15:02 schrieb el es:
> On 24/08/17 13:26, Sven Barth via fpc-pascal wrote:
> [...]
>> Note: FPC (and Delphi) has a single fixed point type which is
>> Currency. AFAIK it uses four digits after the comma and 28 in front
>> of it.
>>
>> Regards, Sven
>>
> There was a project I remember, that I was told, for some e.g. tax purposes,
> 4 digits after the decimal point are not enough to round them properly...
> That is because, the calculation of e.g. VAT has to work out both ways (total=net+VAT and
> has to work out in every way, including when a bigger package is split into smaller units)
> and 4 decimal digits are not always enough to ensure this (and the program had to work
> internationally with all the different tax rules too) for arbitrarily large quantities, prices and tax bands.
>
> I don't remember the exact details (it long time ago and couple of workplaces ago), of what they did,
> but the team developing it (in D7) was pretty stressed...

When you do calculations of actual values of
on-board securities, you need 8 digits after the decimal point
and more, because the stock quotation already has 6 digits after
the decimal point, and you have to multiply that with the quantity,
which has decimal parts, too.

With decimal arithmetic, rounded multiplication is pretty simple:
you multiply the two items, giving a result with one decimal digit
more as you need, then you round the result.

In PL/1:

    value = round (multiply (quantity, quotation, 15, 3), 2);

gives the rounded value in Euro, no matter how many digits after
the decimal point quantity and quotation had. The multiply function
will take care of the proper scaling and stop after the third digit
which is sufficient to round at the second position.

Kind regards

Bernd


> -l.
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list