<p>Do you know an easy and straight-forward method/sub/module which allows me to convert a number (say 1234567.89) to an easily readable form - something like 1.23M?</p>

<p>Right now I can do this by making several comparisons, but I'm not happy with my method:</p>

<pre><code>if($bytes &gt; 1000000000){ 
   $bytes = ( sprintf( "%0.2f", $bytes/1000000000 )). " Gb/s";                   
}
elsif ($bytes &gt; 1000000){       
   $bytes = ( sprintf( "%0.2f", $bytes/1000000 )). " Mb/s"; 
}
elsif ($bytes &gt; 1000){
   $bytes = ( sprintf( "%0.2f", $bytes/1000 )). " Kb/s"; 
}
else{ 
   $bytes = sprintf( "%0.2f", $bytes ). "b/s";
}                                                                  
</code></pre>

<p>Thank you for your help!</p>

The
Number::Bytes::Human
module should be able to help you out.
An example of how to use it can be found in its synopsis:
```
```
use Number::Bytes::Human qw(format_bytes);

  $size = format_bytes(0); # '0'
  $size = format_bytes(2*1024); # '2.0K'

  $size = format_bytes(1_234_890, bs => 1000); # '1.3M'
  $size = format_bytes(1E9, bs => 1000); # '1.0G'

  # the OO way
  $human = Number::Bytes::Human->new(bs => 1000, si => 1);
  $size = $human->format(1E7); # '10MB'
  $human->set_options(zero => '-');
  $size = $human->format(0); # '-'
```
```