(Courriels de diversion: <representeraient@emmêles-enorgueillissez.com> <intimant@demilitarisant-revolvers.com> <ethnies@fiance-fripon.com> <etudiez@potence-plusieurs.com> <pechez@renfrogne-deferlons.com> <vieillissiez@haïront-ligotes.com> <libertines@emetteurs-batteurs.com> <faufilerons@theoriserais-arriere-grand-pere.com> <foirer@recrire-regonfla.com> <abjurer@moussaillons-regretteront.com> )
On Wed, 2 Oct 2002, Jean-marc Harang wrote:
> je dirais trunc mais sans garantie. Court-jus, tu as ma bible Perl, tu
> réponds, stp ? :-)
Non, ya pas de trunc en Perl
> sinon tu fais un print de la partie entière et tu reconvertis la chaine en
> entier.... :-))
Ca ca marche.
Et comme il y a plus d'une facon de faire... il existe un module rieng que
pour ca: Math::Round.
Un exemple suit:
#!/bin/perl -wl
use strict;
use Math::Round qw(:all);
foreach my $nb (<DATA>) { test_funcs( $nb); }
sub test_funcs
{ my $nb= shift;
chomp $nb;
print "int($nb) : ", int($nb);
print "sprintf( %d, $nb) : ", sprintf( "%d", $nb);
# apres il faut Math::Round
print "round($nb) : ", round($nb);
print "round_even($nb) : ", round_even($nb);
print "round_odd($nb) : ", round_odd($nb);
print "round_rand($nb) : ", round_rand($nb);
print "\n";
}
__DATA__
2.123
-2.123
2
-2
2.5
-2.5
---------------------------------------------------------------------
Aide sur la liste: <URL:mailto:linux-31-help@CULTe.org>Le CULTe sur le web: <URL:http://www.CULTe.org/>