Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Alltrim for numeric variables
Message
De
19/06/2001 14:54:44
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00520367
Message ID:
00521183
Vues:
21
>>>? ">" + transform( my_variable ) + "<" >
>>
>>Recently I had a nasty surprise with this. I had a loop to name the variables to use in a macro (because I had to loop through field1, field2, field3, ..., field45), and I used
>>
cFieldName="field"+tran(i)
>>where i was the loop counter. To my surprise, when it ran it banged on
>>
cValue=eval(cFieldName)
>>because the value in cFieldName was Field1.000000000 - probably the loop counter got created with some accidental (?) decimals. Luckily, I knew that the structure of the table will not change and that field1 is the 10th field, so I used
>>
cValue=eval(fields(i+9))
>>instead. Still, this accident got me thinking... will tran(integer) always yield a string representation of a number without a decimal point, or is it something to watch out for and code around.
>
>Dragan,
>
>It's a known fact, that transform has a bug. See this KB artcile for details

Seems to be the slight differences in the value of i tend to be displayed to the maximal precision in transform() without the second parameter - they actually are there, but usually not visible and not displayed. Here's the routine from the article, slightly modified:
CLEAR
cCompatible = SET("COMPATIBLE")
SET COMPATIBLE OFF
? "Precision automatically jumps to 15 decimal places "
? "with overflows displayed at 1.6"

FOR i = 1 TO 3 STEP .1
	? i, i-round(i,15), TRANSFORM(i)
ENDFOR
SET COMPATIBLE &cCompatible 
Putting any other value for the number of decimals in round(), I had a perfect column of zeros, only for 15 it's a -1e-15 there, for values of 1.5 and 2.5. Still the error I had didn't come from any accumulation of 0.1's - it kicked in with the initial value. If Transform() only respected the Set Decimals, it'd be allright.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform