Add thousands separator commas to output

This commit is contained in:
Dan Church 2022-09-13 11:50:10 -05:00
parent 93561ca90a
commit 8059dc4455
Signed by: h3xx
GPG Key ID: EA2BF379CD2CDBD0
2 changed files with 15 additions and 2 deletions

View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- Limit "Skipped" output to only summary
- Omit output of progress bar unless -v flag is present
- Add thousands separator commas to output
## [3.0.0]

View File

@ -238,8 +238,8 @@ MAIN: {
$freed_bytes += $inst->bytes_freed;
}
printf STDERR "freed %d bytes (%0.4G %s)\n",
$freed_bytes,
printf STDERR "freed %s bytes (%0.4G %s)\n",
Directory::Simplify::Utils::addcommas($freed_bytes),
Directory::Simplify::Utils::hr_size($freed_bytes)
if $print_freed or $verbose;
}
@ -248,6 +248,18 @@ package Directory::Simplify::Utils;
use strict;
use warnings;
sub addcommas {
my @added;
foreach my $num (@_) {
# don't split anything after the decimal
my @parts = split /\./, $num;
while ($parts[0] =~ s/(\d)(\d{3}(?:\D|$))/$1,$2/) {
}
push @added, (join '.', @parts);
}
wantarray ? @added : $added[0]
}
sub hr_size {
my $sz = shift;
my @sizes = qw/ B KB MB GB TB PB EB ZB YB /;