Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Currency calculations. Bug?
Message
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01505515
Message ID:
01505522
Views:
64
This message has been marked as a message which has helped to the initial question of the thread.
See if these results help a bit:
CLEAR
CLOSE tables all
CREATE CURSOR testcrs (fldn N(12,4), fldcur Y) 
ln=300000
SET DECIMALS TO 10
INSERT INTO testcrs VALUES (ln,ln)
n1=43.05
n2=44.06

?"Variable:         ", n2/n1 * m.ln, m.ln * n2/n1		&& ~same
?"Variable:         ", ROUND(n2/n1,4), n2/n1		&& ~same
? "1.0235 * ln"      , 1.0235*m.ln
? "1.023461091754 * ln"      , 1.023461091754*m.ln


?"Variable:         ", ROUND(n2/n1,4) * m.ln, m.ln * n2/n1		&& ~same

?"Numeric field:    ", n2/n1 * fldn, fldn * n2/n1	&& ~same

?"Currency field:   ", n2/n1 * fldcur, fldcur * n2/n1     && 307050.0000,        307038.3275        different results ?!
?"Currency2Numeric: ", n2/n1 * MTON(fldcur), MTON(fldcur) * n2/n1  && ~same
According to Currency Type

If you specify more than four decimal places in a currency expression, Visual FoxPro rounds to the expression to four places before evaluating the expression. In the example, the variable moremoney is internally rounded to 675.4389.



>It is expected that result of calculations may be slightly different depending on the initial precision, but the difference in tens units?
>Anyone can shed light on it?
>
>
>* Tested in versions VFP5, VFP7, VFP 9 and VFP 9 Sp1
>CLEAR
>CLOSE tables all
>CREATE CURSOR testcrs (fldn N(12,4), fldcur Y) 
>ln=300000
>
>INSERT INTO testcrs VALUES (ln,ln)
>n1=43.05
>n2=44.06
>
>?"Variable:         ", n2/n1 * ln, ln * n2/n1		&& ~same
>?"Numeric field:    ", n2/n1 * fldn, fldn * n2/n1	&& ~same
>
>?"Currency field:   ", n2/n1 * fldcur, fldcur * n2/n1     && 307050.0000,        307038.3275        different results ?!
>?"Currency2Numeric: ", n2/n1 * MTON(fldcur), MTON(fldcur) * n2/n1  && ~same
>
>
>
>Thanks in advance
>
>Yuri Rubinov
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform