Money type

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Jan 3 17:14:06 UTC 2020


And please forget the idea that fixed point is exact, it most 
certainly is not! :-)

Let me give an example:

Assume that you have 21% VAT and prices are given including tax, 
then in order to find the price without VAT you have to calculate 
price/1.21, but in fixed point that becomes price*100/121 which 
will have a remainder. So then you also have to deal with the 
remainder, so not exact at all.

If you want the price without VAT, rounded you'll have to do:

    (price * 200 / 242 + 1) / 2

If you want to deal with the price without VAT with no rounding, 
you will have to emulate rational numbers...




More information about the Digitalmars-d mailing list