Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print second digit after decimal point with Number::Bytes::Human?

Tags:

perl

I'm using this code to convert bytes into more readable format, e.g. 155K, 1.5M, 1.5G, but can't figure out from the explanation on CPAN how the converted values to be printed to the second digit after the decimal point and to be rounded.

use strict; 
use warnings;
use Number::Bytes::Human qw(format_bytes);

my $bytes = format_bytes(-s $file);
like image 507
thebourneid Avatar asked Oct 16 '25 16:10

thebourneid


1 Answers

I am able to control the number of decimals using Number::Format:

use Number::Format qw(format_bytes);
print format_bytes(-s $file, precision => 2);

Number::Bytes::Human does have a round option, but I do not see an option to set the precision.

like image 197
toolic Avatar answered Oct 19 '25 00:10

toolic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!