Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
When to choose currency data type?
Message
De
20/08/2009 14:15:16
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
20/08/2009 13:01:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01419279
Message ID:
01419298
Vues:
90
>Hi,
>
>I can find very little discussion about using Currency data type field when designing table structure in all my VFP books.
>
>VFP9 help's tip says: "For precise financial calculations, use the Currency data type instead of Numeric. "
>But I know currency data is always calculated with 4 decimal places... and that can cause calculation like $1000 * (1/3) to end up inaccurately...
>
>So, what are the pros and cons of using currency data type? What should I consider when choosing between numeric and currency data type?

It should be faster, if all the calculation is done in currency, because it's basically a 64-bit integer, just divided or multiplied by 10000 when really necessary (like in multiplication or division, or when passed to math functions). Four lowest digits (out of theoretical 18.5) serve as decimals, whereas in real life you should use only two - so with two extra decimals you should be fine, precision wise, for anything financial (except, perhaps, when deriving daily interest rates from the annual), while having the processing speed and compact storage (8 bytes) of integers.

You lose most of the speed gains as soon as there's a number of another type in an expression - it gets converted to, I guess, standard IEEE floating format, which gets it a few digits shorter, as it needs a few of the 64 bits to store the exponent. And conversion, of course, takes a few cycles.

Maybe you misread "precise financial calculations" as "precise, financial calculations" :). Finance have their own definition of precision, which is not exactly in the same universe with the mathematical precision.

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