[Bioperl-l] perl question

Andreas Kahari ak at ebi.ac.uk
Mon Nov 5 13:56:24 UTC 2007


On Mon, Nov 05, 2007 at 01:24:25PM +0000, Sendu Bala wrote:
> Andreas Kahari wrote:
> > On Mon, Nov 05, 2007 at 05:50:04PM +0530, neeti somaiya wrote:
> >> Again a perl question, and maybe a very trivial one.
> >> How do I terminate a number like 3.1232010098 to only 3 decimal places in
> >> perl?
> > 
> > When displaying:
> > 
> >   printf( "The number is %.3f\n", $number );
> > 
> > When making a string:
> > 
> >   my $string = sprintf( "%.3f", $number );
> > 
> > 
> > BTW, this is cutting, not rounding.
> 
> (s)printf rounds (ie. doesn't simply truncate), though for critical 
> applications you should use your own rounding algorithm.

They do indeed.  Mea culpa.


Andreas

-- 
Andreas Kähäri :: Ensembl Software Developer
European Bioinformatics Institute (EMBL-EBI)
--------------------------------------------



More information about the Bioperl-l mailing list