Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert number to a char string
Message
De
21/12/2019 18:25:33
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01672170
Message ID:
01672392
Vues:
41
>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))
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform