[Bioperl-l] perl question

Sendu Bala bix at sendu.me.uk
Mon Nov 5 13:24:25 UTC 2007


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.




More information about the Bioperl-l mailing list