Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Precise Calculation
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00058291
Message ID:
00058383
Views:
28
>>I need to convert from local to foreign currency and vice vesa.
>>The problem I faced was it wouldn't be accurate when converting the second
>>time.
>>
>>First, I need to convert from foreign to local and store the result(in 2
>>dec. places)
>>into the table.
>>The second time I want to convert from local(from table) to foreign and
>>display on
>>screen, but the result will not be the same as the original value.
>>
>>Eg:
>> - where exchange rate 99.9999 format
>>1st round - foreign $10.00 --> local $5.55 (store into table
>>with ROUND( ) )
>>2nd round - local $5.55 --> foreign $9.99 (should be $10.00
>>originally)
>>
>>Any better ways to get more accurate results? Pls advise, thanks.
>Alvin,
>
>Do not store the values with 2 decimal places, store them with 4 or more decimal places, round them when you display or print them. This will give you higher accuracy in converting back and forth while still giving you 2 decimals in the display. The reason you are getting rounding errors is that you are throwing the accuracy away when you store only 2 decimal places.


Alvin,

Jim's method will help, but mathematically the error will increase each time you do a conversion. Each conversion that you do you are storing a 2 or 4 decimal approximation to the "real" value. This this will magnify the error each time you do a conversion.

If you routinely convert currencies back, you could store the original value and your user's would be happy because the values would match. I am not sure if this can be done since I don't know the full context of your application.
Previous
Reply
Map
View

Click here to load this message in the networking platform