+
+sub parseValue {
+ if (defined $_[0] && $_[0] =~ /^(-?\d+(?:\.\d+)?)([khMG])?$/){
+ return $1 unless defined $2;
+ return $1*100 if $2 eq 'h';
+ return $1*1000 if $2 eq 'k';
+ return $1*1000000 if $2 eq 'M';
+ return $1*1000000000 if $2 eq 'G';
+ }
+ return $_[0];
+}
+
+sub prettyValue {
+ my ($value,$decimals) = @_;
+ return sprintf('%.3e',$value) if $value > 1000000000000000;
+ my $unit = '';
+ my @units = ('k','M','G','T');
+ for (my $i = 0; $value >= 1000 && $i < 4;$i++){
+ $value /= 1000;
+ $unit = $units[$i];
+ }
+ unless (defined $decimals){
+ $decimals = '.0';
+ $decimals = '.1' if $value < 100 && $unit;
+ $decimals = '.2' if $value < 10 && $unit;
+ }
+
+ return sprintf('%'.$decimals.'f%s', $value,$unit);
+}
+
+