Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Losing decimals when filling spreadsheet
Message
From
06/06/2002 07:48:59
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00664829
Message ID:
00665346
Views:
22
>Found the problem. To me, it's a VFP bug, but it might be by design.
>
>When using OLE automation to fill a spreadsheet, if the variable is typed "Currency" VFP rounds to 2 decimal places before sending to Excel. You can't even fool VFP by reading the value into memory and then sending to Excel because VFP keeps the variable typed as currency.
>
>If you create a temp sql cursor from a table with currency values, the values in the temp cursor are typed as currency. I had to define some variables as numeric (99.9999 AS yPremium) and created another variable as currency (yPremium AS premium) used the READWRITE keyword to make a cursor I could write to and scanned the cursor replacing the yPreimum with Premium. Then when I used the yPremium variable in the statement it was typed as numeric.
>
>I guess I could have changed the value like this:
>
>lnValue = VAL(STR(yPremium,7,4)) to change it also, but thought of it later.
>
>So if you need to export more than 2 decimals to Excel make sure you don't store them as currency.

You can convert to numeric with mton(), before converting to Excel.

HTH, Hilmar.
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