Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Currency data type, BUG or FEATURE?
Message
De
10/03/2006 08:28:50
 
 
À
09/03/2006 21:20:11
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01102959
Message ID:
01103048
Vues:
18
So are ther any advantages in using currency as a data type, instead numeric or double? Apart from output format with the currency sign?

>Almost any calculation that involves currency will convert all intermediate results to currency (4 decimals). Repeat this with a calculator, and see what you get - rounding all intermediate results to 4 digits. You even get different results if you change the order of the factors, putting the currency value at the end.
>
>So, if you need to calculate with more decimals, yes, you need some conversion. Instead of cast(), you can also use mton(). By the way, an alternative for repro code is to assign a constant with $:
>
>
>UnitPrice = $35760
>...
>
>
>I would not consider this a bug (although it can cause nasty bugs in your own code, if you don't remember it!) - that is the way currency data type is inherently handled. With currency data type, addition and subtraction is inherently exact; multiplication and division is not.
>
>Saludos,
>
>Hilmar.
>
>>Hi all,
>>
>>I have built the following simple repro code of something that is driving me crazy:
>>
>>
>>create Cursor temp (unitPrice Y, quantity B(5), discount B(5))
>>
>>insert into temp values (35760, 10, 28.221)
>>
>>? UnitPrice                 * quantity * (1 - (discount/100))    && displays 256685.28
>>? cast(UnitPrice as double) * quantity * (1 - (discount/100))    && displays 256681.704
>>
>>
>>There is a difference of almost 4 between the 2 calculations. I have a lot of code that makes calculations, and if I have to CAST every bit of it, it's going to take quite a time. Is there a simple solution to this? Is this a BUG or a FEATURE?
>>
>>Thanks a lot,
>>Javier.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform