Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a truncate function?
Message
De
25/03/2006 14:56:58
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01107703
Message ID:
01107710
Vues:
18
>Hi.
>is there a numeric truncate function in VFP as in:
>Truncate(2.347,2) returns 2.34
>Truncate(2.341,2) returns 2.34
>Truncate (78.1297,3) returns 78.129
>Similar to round but without the rounding bit

I think not, but you can use the int() function:
? int(2.347 * 100) / 100
If you need this often, create your UDF:
? truncate(2.347, 2)

function truncate(tnNumber, tnDecimals)
return int(tnNumber * 10 ^ tnDecimals) / 10 ^ tnDecimals
See also floor() - same as int() for positive numbers, but behaviour is different in the case of negative numbers.
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