diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 5e8412f8b..70af296c0 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -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]); diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index e2f285712..03850e037 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -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; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 1a652a839..70f806ff3 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1500,7 +1500,7 @@ sub recalculateRating { [$self->getId] ); - my $average = round($sum/$count); + my $average = sprintf('%.0f', $sum/$count); $self->update({rating=>$average}); } diff --git a/lib/WebGUI/Asset/Wobject/Poll.pm b/lib/WebGUI/Asset/Wobject/Poll.pm index a74767c60..dfa920fc7 100644 --- a/lib/WebGUI/Asset/Wobject/Poll.pm +++ b/lib/WebGUI/Asset/Wobject/Poll.pm @@ -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)); diff --git a/lib/WebGUI/Asset/Wobject/StockData.pm b/lib/WebGUI/Asset/Wobject/StockData.pm index 0d6cef4e2..3e80499cf 100644 --- a/lib/WebGUI/Asset/Wobject/StockData.pm +++ b/lib/WebGUI/Asset/Wobject/StockData.pm @@ -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"})); diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 31ec44f1b..5532ef436 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -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; } diff --git a/lib/WebGUI/Image/Graph/XYGraph/Bar.pm b/lib/WebGUI/Image/Graph/XYGraph/Bar.pm index 32f77e965..a7ad738c7 100644 --- a/lib/WebGUI/Image/Graph/XYGraph/Bar.pm +++ b/lib/WebGUI/Image/Graph/XYGraph/Bar.pm @@ -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 } } diff --git a/lib/WebGUI/Operation/Help.pm b/lib/WebGUI/Operation/Help.pm index 82b2567b8..a82444409 100644 --- a/lib/WebGUI/Operation/Help.pm +++ b/lib/WebGUI/Operation/Help.pm @@ -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 = '
';
- 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) {
diff --git a/lib/WebGUI/Paginator.pm b/lib/WebGUI/Paginator.pm
index fd0d9d9fb..513e40903 100644
--- a/lib/WebGUI/Paginator.pm
+++ b/lib/WebGUI/Paginator.pm
@@ -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;
diff --git a/lib/WebGUI/Role/Asset/Comments.pm b/lib/WebGUI/Role/Asset/Comments.pm
index ca54fd16f..83c50528c 100644
--- a/lib/WebGUI/Role/Asset/Comments.pm
+++ b/lib/WebGUI/Role/Asset/Comments.pm
@@ -193,7 +193,7 @@ Returns the HTML needed to render the average rating icon.
sub getAverageCommentRatingIcon {
my $self = shift;
- return q{ };
+ return q{ };
}
diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm
index d56dfd092..19e7768a6 100644
--- a/lib/WebGUI/Session/DateTime.pm
+++ b/lib/WebGUI/Session/DateTime.pm
@@ -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
diff --git a/lib/WebGUI/Utility.pm b/lib/WebGUI/Utility.pm
index 79ba62895..1678fa680 100644
--- a/lib/WebGUI/Utility.pm
+++ b/lib/WebGUI/Utility.pm
@@ -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 |