summaryrefslogtreecommitdiff
path: root/FS/FS/UI
diff options
context:
space:
mode:
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
###