Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
When to choose currency data type?
Message
De
21/08/2009 04:38:01
 
 
À
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:
01419484
Vues:
82
>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?

When you want to have an exact sum, use Currency.

For moltiplication is better to use numeric or double.
CREATE CURSOR TABLE (NUMERIC N(12,4),CURRENCY Y)
INSERT INTO TABLE VALUES (0.1,$0.1)

numericSum = 0.0000
numericSumRound = 0
currencySum = $0
FOR k=0 TO 9
	numericSum=m.numericSum + TABLE.NUMERIC
	numericSumRound =ROUND(m.numericSumRound + TABLE.NUMERIC,4)
	currencySum =m.currencySum + TABLE.NUMERIC
NEXT

CLEAR
ACTIVATE SCREEN
? EMPTY(m.numericSum - 1.0000)
? EMPTY(ROUND(m.numericSum - 1.0000,4))
? EMPTY(m.numericSumRound - 1.0000)
? EMPTY(m.currencySum - 1.0000)
ROUND() may seem a solution, but no it is !
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform