Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When to choose currency data type?
Message
From
20/08/2009 22:23:35
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
20/08/2009 13:01:18
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01419279
Message ID:
01419437
Views:
77
>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?

With currency, you get absolute precision when you add or subtract - no rounding error in the last digit, due to internal data conversion issues.

Personally I like to use currency in tables, not only for money, but also for quantities in stock (assuming you don't need more than 4 digits).

Please note that in most calculations, if one of the operators is currency, the entire result is converted to currency. Precision may be lost, if you need more than 4 decimals - or if you expect 1 / 3 * 3 to be 1, for example (try: ? $1 / 3 * 3). Sometimes you have to analyze step by step what calculations are being done. You can convert currency to "normal" numbers and back, with mton() and ntom().
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform