Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transform(10) eat my ZERO
Message
De
17/01/2004 21:16:30
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
17/01/2004 20:57:55
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00867862
Message ID:
00867875
Vues:
16
>Hi,
>Thank you.
>Just for your info, SET DECIMAL TO 2 will cause TRANS(10) return "10.00" but not 10.
>
>Thank you

Because of some inconsistent results, it may be convenient to write your own UDF to replace the use of transform() with a single parameter. (transform with the additional picture parameter is quite trustworthy, AFAIK; for instance: transform(SomeNumber, "###,###.##")

If you don't need decimals, you can use alltrim(str(10)).

Otherwise, to show only those digits that are required, you can use something like he following function, which I quickly built together right now (which means it isn't thoroughly tested):
FUNCTION MyTrans(tnNumber)
* Convert number to text, retaining only significant digits
* Replacement for Trans(Number), which is not always trustworthy.
	local lcResult
	lcResult = alltrim(str(tnNumber, 20, 10))
	lcResult = strtran(lcResult, "0", " ")
	lcResult = alltrim(lcResult)
	lcResult = strtran(lcResult, " ", "0")
	if left(lcResult, 1) = set("point")
		lcResult = "0" + lcResult
	endif
	if right(lcResult, 1) = set("point")
		lcResult = left(lcResult, len(lcResult) - 1)
	endif
	return lcResult
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform