2011-06-25 23 views
2

我正在使用此代碼將字節轉換爲更具可讀性的格式,例如155K,1.5M,1.5G,但無法從CPAN上的解釋中找出如何將轉換後的值打印到小數點後的第二位並舍入。 謝謝。Perl編號::字節::人類

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

my $bytes = format_bytes(-s $file); 
+1

這個特殊的模塊是alpha,這可能值得考慮。 – TLP

回答

5

我能夠控制使用Number::Format的小數點後的位數:

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

Number::Bytes::Human確實有round選項,但我沒有看到一個選項來設置精度。

+1

使用Number :: Format實際上更適合我的需求。很有幫助。非常感謝。 – thebourneid