remove WebGUI::Utility::round
This commit is contained in:
parent
ddf0419836
commit
fadc4f34ea
13 changed files with 34 additions and 87 deletions
|
|
@ -536,7 +536,7 @@ sub setRatings {
|
|||
my $sum = $db->quickScalar("select sum(rating) $sql", [$self->getId,$category]);
|
||||
my $count = $db->quickScalar("select count(*) $sql", [$self->getId,$category]);
|
||||
|
||||
my $half = round($count/2);
|
||||
my $half = sprintf('%.0f', $count/2);
|
||||
my $mean = $sum / ($count || 1);
|
||||
my $median = $db->quickScalar("select rating $sql order by rating limit $half,1",[$self->getId,$category]);
|
||||
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ sub formatDuration {
|
|||
if ($hours[0]) {
|
||||
$formattedDuration = join ' ', @hours;
|
||||
}
|
||||
my $minutes = round(($duration - $hours)/60)*60;
|
||||
my $minutes = sprintf('%.0f', ($duration - $hours) / 60 ) * 60;
|
||||
my @minutes = $datetime->secondsToInterval($minutes);
|
||||
if ($minutes[0]) {
|
||||
$formattedDuration .= ', ', if $formattedDuration;
|
||||
|
|
|
|||
|
|
@ -1500,7 +1500,7 @@ sub recalculateRating {
|
|||
[$self->getId]
|
||||
);
|
||||
|
||||
my $average = round($sum/$count);
|
||||
my $average = sprintf('%.0f', $sum/$count);
|
||||
$self->update({rating=>$average});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -502,9 +502,9 @@ sub view {
|
|||
push(@answers,{
|
||||
"answer.form"=>WebGUI::Form::radio($self->session,{name=>"answer",value=>"a".$i}),
|
||||
"answer.text"=>$self->get('a'.$i),
|
||||
"answer.graphWidth"=>round($self->get("graphWidth")*$tally/$totalResponses),
|
||||
"answer.graphWidth"=>sprintf('%.0f', $self->get("graphWidth")*$tally/$totalResponses),
|
||||
"answer.number"=>$i,
|
||||
"answer.percent"=>round(100*$tally/$totalResponses),
|
||||
"answer.percent"=>sprintf('%0.f', 100*$tally/$totalResponses),
|
||||
"answer.total"=>($tally+0)
|
||||
});
|
||||
push(@dataset, ($tally+0));
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ sub _appendStockVars {
|
|||
}
|
||||
$hash->{'stocks.p_change'} = _na($data->{$symbol,"p_change"});
|
||||
$hash->{'stocks.volume'} = _na($data->{$symbol,"volume"});
|
||||
$hash->{'stocks.volume.millions'} = _na(WebGUI::Utility::round(($hash->{'stocks.volume'}/1000000),2));
|
||||
$hash->{'stocks.volume.millions'} = _na(sprintf('%.2f', $hash->{'stocks.volume'}/1000000));
|
||||
$hash->{'stocks.avg_vol'} = _na($data->{$symbol,"avg_vol"});
|
||||
$hash->{'stocks.bid'} = _na($data->{$symbol,"bid"});
|
||||
$hash->{'stocks.ask'} = _na(Number::Format::format_number($data->{$symbol,"ask"}));
|
||||
|
|
|
|||
|
|
@ -2252,7 +2252,7 @@ END_SQL
|
|||
&& WebGUI::DateTime->new( $self->session, $row->{endDate} )->toUserTimeZone,
|
||||
response_user_name => ( $row->{userId} eq '1' ) ? $row->{ipAddress} : $row->{username},
|
||||
response_count_correct => $correctCount,
|
||||
response_percent => round( ( $correctCount / $var->{question_count} ) * 100 ),
|
||||
response_percent => sprintf('%.0f', ( $correctCount / $var->{question_count} ) * 100 ),
|
||||
};
|
||||
}
|
||||
$var->{response_loop} = \@responseloop;
|
||||
|
|
@ -2302,7 +2302,7 @@ sub www_viewStatisticalOverview {
|
|||
[$sectionIndex,$questionIndex,$answerIndex]);
|
||||
my $responsePercent;
|
||||
if ($totalResponses) {
|
||||
$responsePercent = round(($numResponses/$totalResponses)*100);
|
||||
$responsePercent = sprintf('%.0f', ($numResponses/$totalResponses)*100);
|
||||
} else {
|
||||
$responsePercent = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ sub getAnchorSpacing {
|
|||
|
||||
my $numberOfGroups = List::Util::max(map {scalar @$_} @{$self->getDataset});
|
||||
|
||||
my $spacing = round(($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing);
|
||||
my $spacing = sprintf('%.0f', ($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing);
|
||||
|
||||
return {
|
||||
x => $spacing,
|
||||
|
|
@ -320,7 +320,7 @@ sub getFirstAnchorLocation {
|
|||
my $self = shift;
|
||||
|
||||
return {
|
||||
x => round($self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2),
|
||||
x => sprintf('%.0f', $self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2),
|
||||
y => $self->getChartOffset->{y} + $self->getChartHeight
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ A scalar ref to the array of data that will be broken into columns.
|
|||
sub _columnar {
|
||||
my ($columns, $list) = @_;
|
||||
my @entries = @{ $list };
|
||||
my $fraction = round(@entries/$columns + 0.50);
|
||||
my $fraction = sprintf('%.0f', @entries/$columns + 0.50);
|
||||
my $output = '<tr><td valign="top">';
|
||||
@entries = sort { $a->{name} cmp $b->{name} } @entries;
|
||||
my $i = 0;
|
||||
|
|
@ -369,7 +369,7 @@ sub www_viewHelpIndex {
|
|||
}
|
||||
}
|
||||
my $output = '<table width="100%" class="content"><tr><td valign="top">';
|
||||
my $halfway = round(@helpIndex / 2);
|
||||
my $halfway = sprintf('%.0f', @helpIndex / 2);
|
||||
my $i = 0;
|
||||
@helpIndex = sort { $a->[2] cmp $b->[2] } @helpIndex;
|
||||
foreach my $helpEntry (@helpIndex) {
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ sub getPageLinks {
|
|||
if ($limit) {
|
||||
my $output;
|
||||
my $i = 1;
|
||||
my $minPage = $self->getPageNumber - round($limit/2);
|
||||
my $minPage = $self->getPageNumber - sprintf('%.0f', $limit/2);
|
||||
my $start = ($minPage > 0) ? $minPage : 1;
|
||||
my $maxPage = $start + $limit - 1;
|
||||
my $end = ($maxPage < $self->getPageNumber) ? $self->getPageNumber : $maxPage;
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ Returns the HTML needed to render the average rating icon.
|
|||
|
||||
sub getAverageCommentRatingIcon {
|
||||
my $self = shift;
|
||||
return q{<img src="}.$self->session->url->extras('form/CommentRating/'.round($self->get('averageCommentRating'),0).'.png').q{" style="vertical-align: middle;" alt="}.$self->get('averageCommentRating').q{" />};
|
||||
return q{<img src="}.$self->session->url->extras('form/CommentRating/'.sprintf('%.0f', $self->get('averageCommentRating')).'.png').q{" style="vertical-align: middle;" alt="}.$self->get('averageCommentRating').q{" />};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use DateTime::TimeZone;
|
|||
use Scalar::Util qw( weaken );
|
||||
use Tie::IxHash;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Utility qw(round isIn);
|
||||
use WebGUI::Utility qw(isIn);
|
||||
use Scalar::Util qw(weaken);
|
||||
|
||||
|
||||
|
|
@ -815,40 +815,25 @@ The number of seconds in the interval.
|
|||
|
||||
=cut
|
||||
|
||||
my %intervals = (
|
||||
31536000 => "703", # years
|
||||
2592000 => "702", # months
|
||||
604800 => "701", # weeks
|
||||
86400 => "700", # days
|
||||
3600 => "706", # hours
|
||||
60 => "705", # minutes
|
||||
);
|
||||
|
||||
sub secondsToInterval {
|
||||
my $self = shift;
|
||||
my $seconds = shift;
|
||||
my $self = shift;
|
||||
my $seconds = shift;
|
||||
my $i18n = WebGUI::International->new($self->session, 'WebGUI');
|
||||
my ($interval, $units);
|
||||
if ($seconds >= 31536000) {
|
||||
$interval = round($seconds/31536000);
|
||||
$units = $i18n->get("703");
|
||||
}
|
||||
elsif ($seconds >= 2592000) {
|
||||
$interval = round($seconds/2592000);
|
||||
$units = $i18n->get("702");
|
||||
}
|
||||
elsif ($seconds >= 604800) {
|
||||
$interval = round($seconds/604800);
|
||||
$units = $i18n->get("701");
|
||||
}
|
||||
elsif ($seconds >= 86400) {
|
||||
$interval = round($seconds/86400);
|
||||
$units = $i18n->get("700");
|
||||
for my $unit (sort { $b <=> $a } keys %intervals) {
|
||||
if ($seconds > $unit) {
|
||||
return (sprintf('%.0f', $seconds / $unit), $i18n->get($intervals{$unit}));
|
||||
}
|
||||
}
|
||||
elsif ($seconds >= 3600) {
|
||||
$interval = round($seconds/3600);
|
||||
$units = $i18n->get("706");
|
||||
}
|
||||
elsif ($seconds >= 60) {
|
||||
$interval = round($seconds/60);
|
||||
$units = $i18n->get("705");
|
||||
}
|
||||
else {
|
||||
$interval = $seconds;
|
||||
$units = $i18n->get("704");
|
||||
}
|
||||
return ($interval, $units);
|
||||
return ($seconds, $i18n->get("704")); # seconds
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -867,17 +852,9 @@ sub secondsToExactInterval {
|
|||
my $self = shift;
|
||||
my $seconds = shift;
|
||||
my $i18n = WebGUI::International->new($self->session, 'WebGUI');
|
||||
my %units = (
|
||||
31536000 => "703", # years
|
||||
2592000 => "702", # months
|
||||
604800 => "701", # weeks
|
||||
86400 => "700", # days
|
||||
3600 => "706", # hours
|
||||
60 => "705", # minutes
|
||||
);
|
||||
for my $unit (sort { $b <=> $a } keys %units) {
|
||||
for my $unit (sort { $b <=> $a } keys %intervals) {
|
||||
if ($seconds % $unit == 0) {
|
||||
return ($seconds / $unit, $i18n->get($units{$unit}));
|
||||
return ($seconds / $unit, $i18n->get($intervals{$unit}));
|
||||
}
|
||||
}
|
||||
return ($seconds, $i18n->get("704")); # seconds
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use Net::CIDR::Lite;
|
|||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
&sortHash &isIn &round
|
||||
&sortHash &isIn
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -39,7 +39,6 @@ This package provides miscellaneous but useful utilities to the WebGUI programme
|
|||
|
||||
use WebGUI::Utility;
|
||||
$boolean = isIn($value, @array);
|
||||
$rounded = round($number, $digits);
|
||||
%hash = sortHash(%hash);
|
||||
|
||||
=head1 METHODS
|
||||
|
|
@ -72,29 +71,6 @@ sub isIn {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 round ( float [, significantDigits ] )
|
||||
|
||||
Returns an integer after rounding a floating point number.
|
||||
|
||||
=head3 float
|
||||
|
||||
Any floating point number.
|
||||
|
||||
=head3 significantDigits
|
||||
|
||||
The number of digits to leave after the decimal point. Defaults to 0.
|
||||
|
||||
B<NOTE:> If you set this higher than 0 then you'll get back another floating point number rather than an integer.
|
||||
|
||||
=cut
|
||||
|
||||
sub round {
|
||||
my $significantDigits = $_[1] || 0;
|
||||
return sprintf(('%.'.$significantDigits.'f'), $_[0]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 sortHash ( hash )
|
||||
|
||||
Sorts a hash by its values. Returns a Tie::IxHash. You must assign this to
|
||||
|
|
|
|||
|
|
@ -25,12 +25,6 @@ my $session = WebGUI::Test->session;
|
|||
# isIn
|
||||
ok(WebGUI::Utility::isIn("webgui", qw(cars trucks webgui trains)), 'isIn()');
|
||||
|
||||
|
||||
# round
|
||||
is(WebGUI::Utility::round(47.133984233, 0), 47, 'round() - 0 significant digits');
|
||||
is(WebGUI::Utility::round(47.133984233, 3), 47.134, 'round() - multiple significant digits');
|
||||
is(WebGUI::Utility::round(47.6, 0), 48, 'round() - rounds up, too');
|
||||
|
||||
{
|
||||
# Just some basic tests for now.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue