#!/usr/bin/perl -w use bignum; #bug: when rounding e.g. 9.9999999 to 10.000 no attempt is made to # accomodate the extra digit while(<>){ s{(?=1024*1024*1024*1024){ $t="T"; $n/=1024*1024*1024*1024; }elsif($n>=1024*1024*1024){ $t="G"; $n/=1024*1024*1024; }elsif($n>=1024*1024){ $t="M"; $n/=1024*1024; }elsif($n>=1024){ $t="k"; $n/=1024; }else{ $t=""; } if($comma&&length($n)>4){ $n=~s/(\..*)$//; $end=$1; $n=~s/(?<=.)(?=(?:...)+)$/,/g; $n.=$end; } $pad=$w-length($n)-length($t)-$neg; if($pad<0){ $pad=-$pad; if($n=~s/^(.*?)\.(\d*)(.{$pad})$/$1$2/){ ($a,$b)=($1,$2); if(substr($3,0,1)>=5){ ++$b; if(length($b)>length($2)){ ++$a; $b=substr($b,1); } } $n="$a".".$b"; } }elsif($pad>0){ $n=(' 'x$pad).$n; } $n="-$n" if $neg; $n.=$t; $n }egi; print; }