summaryrefslogtreecommitdiff
path: root/FS/FS/UI
diff options
context:
space:
mode:
authorjeff <jeff>2007-04-12 03:16:43 +0000
committerjeff <jeff>2007-04-12 03:16:43 +0000
commit0dd05e9ff98263d2d42b419b1e278a5a3bc594b2 (patch)
treeef42a5ed621c73699e3973fd14ef22abdd3a5823 /FS/FS/UI
parentb611f02e479f4a7f9840f59f773d282b1c13b62f (diff)
input and output on data volume fields specified with k,m,g,or t
Diffstat (limited to 'FS/FS/UI')
-rw-r--r--FS/FS/UI/Web.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm
index 9ddcf14..a05a667 100644
--- a/FS/FS/UI/Web.pm
+++ b/FS/FS/UI/Web.pm
@@ -4,6 +4,7 @@ use strict;
use vars qw($DEBUG $me);
use FS::Conf;
use FS::Record qw(dbdef);
+use Number::Format;
#use vars qw(@ISA);
#use FS::UI
@@ -186,6 +187,31 @@ sub bytecount_unexact {
return(sprintf("%.2f Gbytes", $bc/1000000000));
}
+sub parse_bytecount {
+ my $bc = shift;
+ return $bc if (($bc =~ tr/.//) > 1);
+ $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
+ my $base = $1;
+ return $bc unless length $base;
+ my $exponent = index ' kmgt', lc($2);
+ return $bc if ($exponent < 0 && $2);
+ $exponent = 0 if ($exponent < 0);
+ return $base * 1024 ** $exponent;
+}
+
+sub display_bytecount {
+ my $bc = shift;
+ return $bc unless ($bc =~ /^(\d+)$/);
+ my $conf = new FS::Conf;
+ my $f = new Number::Format;
+ my $precision = $conf->exists('datavolume-significantdigits')
+ ? $conf->config('datavolume-significantdigits')
+ : 3;
+ my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';
+
+ return $f->format_bytes($bc, precision => $precision, unit => $unit);
+}
+
###
# cust_main report subroutines
###