>>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))
>
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham