>Hi,
>
>I am trying to create a generic way to convert any number to a string. Here are some examples, of the number and how they should be as a string:
>
>
>2.4 -> "2.4"
>.00 -> ".00"
>500.32337 -> "500.32337"
>8.342 -> "8.342"
>
>
>I tried TRANSFORM() but the second parameter has to match the number of decimal digits.
>
>Any suggestions?
>
>TIA
What you ask cannot be done because it is put numbers and formats together.
.00 is not a number but a formatting of the number 0.
that can be print in infinite ways
0
.
.0
.00
.000
.0000000 .... 0000 ...
So you have to decide if you want the zeros on the right or not,
but if you not want them you have to decide the maximum of decimals you want.
At this point you get the maximum and remove unnecessary zeros
n=2.4
? LTRIM(STR(m.n,12,10))
? LTRIM(RTRIM(STR(m.n,12,10),"0"))
n=500.32337
? LTRIM(RTRIM(STR(m.n,12,10),"0"))
n=8.342
? LTRIM(RTRIM(STR(m.n,12,10),"0"))
cast not work becuse VFP uses a literal or fixed format
n=.00
? cast(m.n as V(20))
n=8.342
? cast(m.n as V(20))
n=500.32337
? cast(m.n as V(20))
n=2.4
? cast(m.n as V(20))
n=m.n/10
? cast(m.n as V(20))