Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dealing with totals
Message
De
18/12/2007 12:15:47
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
18/12/2007 10:43:24
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01276461
Message ID:
01276478
Vues:
25
>I have always been of the opinion that invoice totals should be calculated when needed rather then stored. The problem is that I get a different result, the so called penny difference, when comparing different types of reports.
>When I review others code I see most people are storing the invoice total and sales tax total and using those totals on reports.
>Any ideas as to what the best approach might be?

Satisfy the accountants, logic be damned.

Actually, it's their set of requirements that dictates a different logic. If you total your taxes per invoice, round them and then total them, you'll get one amount; if you total them per item, round those totals and then total those you may get a different total. The reason for this is simple - the rounding errors have happened in different places, and there's a 99.99% chance that they will be different.

Now what's worse, a tax percentage which, when applied to a total, gives a slightly different amount (usually not much) from what you got, or when you total the same fields from the same records two ways and get different results? In practice, the latter is far worse, because nobody really applies a percentage to your totals to see if it's right - they'll apply them to a few random items just to see if you were calculating them right. But every check begins with checking your totals.

So calculate everything that may have a roundoff error, round it and store so, and never calculate again (unless, of course, the source from which this was calculated changes). Now total this any way you want - you're getting plain old totals and aren't introducing any additional roundoff errors, so they'll total perfectly every time.

I was lucky to have spent only about fifteen hours learning this (by the keyboard, elbow deep in code) back in 1990, when there weren't so many data to care of :).

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform