(Courriels de diversion: <voltages@rejouisse-vende.com> <bafouillerez@eraflures-stoppeur.com> <evacuees@visseraient-jaloux.com> <intermediaires@volontaire-mousseline.com> <troquee@fixais-baptisaient.com> <latinistes@tonifiez-diffamez.com> <retrancherons@sociabilite-apitoya.com> <emulsionner@hilarants-chevrefeuille.com> <regenterent@transpireriez-ereinteriez.com> <strategique@inattendus-gargote.com> )
On Mon, 19 Apr 1999, Jerome Gasperi wrote:
>
> Bonjour,
>
> Y a t'il un equivalent de printf en perl?
> Je veux que 6.9999678 soit approxime comme 7.0 par exemple
> Comment faire simplement?
>
Pour faire de joli fiches :
man perlform
gmmpc1:~> cat /tmp/es.pl
format STDOUT =
NOMBRE @#.#
$a
.
$a = 6.999;
write ;
$a = 18.9999;
write;
gmmpc1:~> perl /tmp/es.pl
NOMBRE 7.0
NOMBRE 19.0
Sinon, tout simplement :
man perlfunc
printf FORMAT, LIST
Equivalent to print FILEHANDLE sprintf(FORMAT,
LIST). The first argument of the list will be
interpreted as the printf format. If use locale
is in effect, the character used for the decimal
point in formatted real numbers is affected by the
LC_NUMERIC locale. See the perllocale manpage.
Don't fall into the trap of using a printf() when
a simple print() would do. The print() is more
efficient, and less error prone.
gmmpc1:~> cat /tmp/es.pl
$a = 6.999;
printf "NOMBRE (printf) %.1f\n", $a;
$a = 108.9871;
printf "NOMBRE (printf) %.1f\n", $a;
gmmpc1:~> perl /tmp/es.pl
NOMBRE (printf) 7.0
NOMBRE (printf) 109.0
| `""'
| Xavier Montagutelli 0--0
| ---------oOOo---()---oOOo----------
| INSA Toulouse - Dpt de Mathematiques Tel: +33 5 61 55 93 38 (HB)
| Complexe scientifique de Rangueil Fax: +33 5 61 55 93 20
| 31077 Toulouse Cedex Mel: montagut@gmm.insa-tlse.fr
_______________________________________________________________________
Le CULTe sur le ouebe: http://savage.iut-blagnac.fr/