ramchand50
17th May 2002, 23:27
string str.amount(10)
domain tfgld.amnt dbl.amount
Scenario=1:
str.amount = "300.50"
string.scan("str.amount", "%f", dbl.amount)
(Now, the result of dbl.amount is 300.50)
Scenario=2:
amount="1,300.50"
string.scan("str.amount", "%f", dbl.amount)
(Now, the result of dbl.amount is 0)
Any idea how to get the scenario-2 working? In otherwards, how to get the values with ',' (thousand symbol) converted to double value?
Appreciate your help.
gguymer
18th May 2002, 00:02
Try this format:
string.scan("str.amount", "ZTZZZVD99", dbl.amount)
9 Reserves a position for a digit; inserts a 0 if there is
no significant digit in that position.
Z Reserves a position for a digit; gives a space if there
is no significant digit in that position. This can be used
both before and after the decimal sign.
V Indicates that the decimal sign must be set on the
position of the V. No decimal sign is shown. If a sign is
required it must immediately follow the V. A 'D', dot or
comma is permitted.
D Reserves a position for the decimal sign, defined in the
data dictionary.
T On the position of each T a thousand sign is placed. The
representation of this sign is defined in the data
dictionary.
popeye
18th May 2002, 01:46
you could write some code to remove the ","s.
while(1)
ret = pos(str.amount,",")
if ret = 0 then
break
endif
str.amount = str.amount(1;ret-1) &
str.amount(ret+1;len(str.amount))
endwhile
string.scan(str.amount, "%f", dbl.amount)
hope this helps.
cheers,
p!
lbencic
20th May 2002, 16:58
You can also use the functions val and lval. val is for doubles, lval for longs.
dbl.amount = val(str.amount)
ramchand50
20th May 2002, 18:01
Thanks everyone, for the feedback.
Just to let you know that Popeye's solution has worked.
gguymer: FYI, I found that the "ZTZZZVD99" works the same way as "%f".
lbenic: FYI, "dbl.amount = val(str.amount)" would return '0', if the value of str.amount is 1,300.50 (since it does't recognize the ',').
NPRao
20th May 2002, 20:25
Hi Lisa,
If you are using the val function for amount="1,300.50" the return value is 1 and the rest of the number is ignored.
jroberts
22nd May 2002, 17:54
I use the %s for splitting strings. %s allows you to specify the delimiters.
Here are examples.
Knowledge Quest has this documented.
double D
long L
string city, prov
string S(80)
long ret
ret = string.scan("string 123 456.78","%s %d %f",S,L,D)
| S contains "string", L contains 123, D contains 456.78
ret = string.scan("string|123|456.78","%s|%d|%f",S,L,D)
| S contains "string", L contains 123, D contains 456.78
ret = string.scan(province,"%s,%s",city,prov)
strip$(shiftr$(prov))
strip$(shiftr$(city))
baanconsultant
22nd May 2002, 23:49
In the format string ZZZZZZ9VD99, the D is . or , as defined in the DD. You can also use ZZZZZZ9V.99 to force a . or ZZZZZ9V,99 to force a ,