Hi Bob,
You wrote to me on 23 Dec 1997:
BS> RS> True, but fractional pence are hard to invoice and even harder to
remit
BS> > They can be required in invoice calculations though... The most common
BS> > occurance of fractional pence is in VAT ([Value Added Tax] which is
ore
BS> > less equivalent to the US state Sales Tax) calculations. The current UK
BS> > rate is 17.5 per cent and the official rules are that when it is
calculat
BS> > on a per line item basis either calculate to 0.5p (round to closest
value
BS> > or 0.1p (round down), with any fraction of a penny in the final total
bei
BS> > ignored.
BS> I included your whole message since someone else already called me on
this
BS>Hand I think it bears repeating. The way I do this sort of
BS>thing is (using HSNIPPETS)...
BS>#include "snipmath.h"
BS> long sale; /* expressed in pennies */
BS> double tax_rate; /* expressed in decimal, e.g. 1% = .01 */
BS> sale = dbl2long((double)sale * (1.0 + tax_rate));
BS> Note that dbl2long() is a specialized version of the
BS>dblround() function Hwhich always rounds doubles properly
BS>to the closest integer - see DBLROUND.HOW, Halso in
BS>SNIPPETS, for more information on how it works.
But that does not match the VAT calculation rules specified above, and
can still result in a variation of several pence from the correct amount
due when VAT is calculated on individual lines (the particular invoice
I'm thinking of is with the accountant so I can't quote it).
Making the unit of money 0.1p and then changing to your code to:
long sale; /* expressed in 0.1 pennies */
double tax_rate; /* expressed in decimal, e.g. 1% = .01 */
sale = dbl2long((double)sale * (tax_rate));
will match one of the sets of rules at the expense of a factor of 10 in
the range of values allowable. The rules involving rounding to 0.5p are
not computer friendly and I believe they are intended for manual
calculations.
George
* SLMR 2.1a * Wishing you a Peaceful and Prosperous New Year
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)
|