X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FUI%2Fbytecount.pm;h=d278dbecc86b7625c7e4a89a9d7d6d490a2bc960;hb=d5967ae3ecfdb0bb1ead8176cfb2760a65c51f2d;hp=233082b082975b7ed5b43357abd24155deea3681;hpb=1748e50c012a65ecb729f15e09169f5d8122a3b1;p=freeside.git diff --git a/FS/FS/UI/bytecount.pm b/FS/FS/UI/bytecount.pm index 233082b08..d278dbecc 100644 --- a/FS/FS/UI/bytecount.pm +++ b/FS/FS/UI/bytecount.pm @@ -3,7 +3,7 @@ package FS::UI::bytecount; use strict; use vars qw($DEBUG $me); use FS::Conf; -use Number::Format; +use Number::Format 1.50; $DEBUG = 0; $me = '[FS::UID::bytecount]'; @@ -42,20 +42,21 @@ sub bytecount_unexact { Accepts a number (digits and a decimal point) possibly followed by k, m, g, or t (and an optional 'b') in either case. Returns a pure number representing -the input or the input itself if unparsable. +the input or the input itself if unparsable. Discards commas as noise. =cut sub parse_bytecount { my $bc = shift; return $bc if (($bc =~ tr/.//) > 1); - $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc; + $bc =~ /^\s*([,\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc; my $base = $1; + $base =~ tr/,//d; 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; + return int($base * 1024 ** $exponent); #bytecounts are integer values } =item display_bytecount AMOUNT @@ -70,7 +71,8 @@ sub display_bytecount { return $bc unless ($bc =~ /^(\d+)$/); my $conf = new FS::Conf; my $f = new Number::Format; - my $precision = $conf->exists('datavolume-significantdigits') + my $precision = ( $conf->exists('datavolume-significantdigits') && + $conf->config('datavolume-significantdigits') =~ /^\s*\d+\s*$/ ) ? $conf->config('datavolume-significantdigits') : 3; my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';