Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Behavior change to TRANSFORM() in VFP7
Message
From
07/10/2004 05:12:37
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00949444
Message ID:
00949460
Views:
23
Borislav,

it's not an error in my function as such, but STR() that rounds up. Where I use it, this behavior is fine, so I simply forgot about it. Here is a better solution
FUNCTION n2c
LPARAMETERS lnInData,lnDecimal
LOCAL lcReturn
  lcReturn=LTRIM(TRANSFORM(lnInData,'99999999999.999999'))
  IF PCOUNT()=1 OR lnDecimal=0
    lcreturn=LEFT(lcReturn,AT(SET('point'),lcReturn)-1)
*   lcreturn=JUSTSTEM(lcreturn) does not work if decimal komma
  ELSE 
    lcreturn=LEFT(lcReturn,AT(SET('point'),lcReturn)+lnDecimal)
  ENDIF
RETURN lcReturn
It is probably possible to make this shorter with iif(), but not very readable.

>Tore,
>I think there is an error in that function:
>
>? NTOC(0.2, 1) &&-> 0.2
>? NTOC(0.2, 0) &&-> 0
>* but
>? NTOC(0.6, 1) &&-> 0.6
>? NTOC(0.6, 1) &&-> 1
>
>
>
>>Hi Neil,
>>
>>I don't know of any behavior change, but if there is, it's probably documented. Why not use transform(0.20,'99999999.9')? Here is a generic function I wrote some years ago:
>>FUNCTION NTOC && Numeric to character, trims the result, optional number of decimals)
>>   PARAMETERS lnInData,lnDecimal
>>   IF PCOUNT()=1
>>      lnDecimal=0
>>   ENDIF
>>RETURN LTRIM(STR(lnInData,10,lnDecimal))
>>ntoc(0.20,1)=0.2
>>ntoc(0.20)=0
>>
>>>I have noticed a behavior change in the TRANSFORM() function in VFP7.
>>>
>>>In VFP6,
>>>
>>>? TRANSFORM(0.20)
>>>0.2
>>>
>>>But in VFP7 (I'm running SP1)
>>>
>>>? TRANSFORM(0.20)
>>>0.20
>>>
>>>This is causing me quite a problem, does anyone know why I'm getting this result and how to rectify it? Is this behavior also in VFP8? The help file still states that trailing zeros after a decimal point should be truncated.
>>>
>>>Neil Shumsky
Previous
Reply
Map
View

Click here to load this message in the networking platform