>>>Hi everybody,
>>>
>>>Suppose I pass a value this way
>>>
>>>'555.55' (as part of the longer string) and pass its type as 'Y'.
>>>
>>>I need to make that string value to be returned as currency value in this case and be correctly passed as currency to other methods (so vartype will detect it as currency).
>>>
>>>I did a quick test in the command window:
>>>
>>>
>>>val = $555.55
>>>=MESSAGEBOX(VARTYPE(val))
>>>
>>>So, it worked, but I want it to be universal. Also, it should not depend on the default language/currency format settings.
>>>
>>>So, may be I should try just casting the value as Y to pass back?
>>>
>>>Thanks in advance.
>>
>>It works for me, and my default language is Bulgarian and currency is лв. :-)
>
>I think CAST will be safer.
>
>This is part of our 'Parse' method code:
>
>
>CASE tcType == "N"
> lvRetVal = VAL(lvRetVal)
> ** FP# 15356 - Strip decimals if there is no remainder
> lvRetVal = IIF(lvRetVal % 1 = 0, INT(lvRetVal), lvRetVal)
>
>There is no 'Y' case currently and I'd like to add it.
>
>Thanks.
If you want to make it
universal, then you probably should pay attention to display settings. CAST() and VAL() work differently in the way they process string into numeric conversions (number or currency). VAL() is aware of display settings, while CAST() expects the value to be represented according to the VFP specification of the data type.
For instance, if a symbol other than the point is
or may be used as a decimal point (as occurs in most of European countries), then an additional previous transformation is required to make sure the string is properly CASTed (this applies to both Y and N data types).
CLEAR
LOCAL lcSetting AS String
m.lcSetting = SET("Point")
SET POINT TO ","
LOCAL lcVal AS String
m.lcVal = "1234,56"
? "m.lcVal =",m.lcVal
? CAST(m.lcVal AS Y)
? VAL(m.lcVal)
? CAST(CHRTRAN(m.lcVal,SET("Point"),".") AS Y)
?
m.lcVal = "1234.56"
? "m.lcVal =",m.lcVal
? CAST(m.lcVal AS Y)
? VAL(m.lcVal)
? CAST(CHRTRAN(m.lcVal,SET("Point"),".") AS Y)
SET POINT TO (m.lcSetting)
----------------------------------
António Tavares Lopes