Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert number to a char string
Message
 
 
To
21/12/2019 18:25:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01672170
Message ID:
01672396
Views:
36
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform