X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;ds=sidebyside;f=ND%2FInclude.pm;fp=ND%2FInclude.pm;h=27d0eb11a912aadf122523295be6ef8951df1fa4;hb=c58e53cf25bbd2ecf5e3cff6a4545aee1dfd1e51;hp=421d81ea044e47f3149b0a4d1c24787235cc0113;hpb=f6418c376095c30c7eda41c3408e4da0a0d83f15;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm index 421d81e..27d0eb1 100644 --- a/ND/Include.pm +++ b/ND/Include.pm @@ -50,14 +50,20 @@ sub parseValue { } sub prettyValue { - my ($value) = @_; + my ($value,$decimals) = @_; my $unit = ''; my @units = ('k','M','G','T'); for (my $i = 0; $value >= 1000;$i++){ $value /= 1000; $unit = $units[$i]; } - return sprintf('%.2f%s', $value,$unit); + unless (defined $decimals){ + $decimals = '.0'; + $decimals = '.1' if $value < 100 && $unit; + $decimals = '.2' if $value < 10 && $unit; + } + + return sprintf('%'.$decimals.'f%s', $value,$unit); }