C.R. wrote:
Does anyone have a routine that will round an integer to a multiple of 5? For example: if number ends in 0 or 5, no rounding is done. If number ends in 1,2 the ones place rounds down to 0. If number ends in 3,4 the ones place rounds up to 5. If number ends in 6,7 the ones place rounds down to 5. If number ends in 8,9 the ones places rounds up to 0 and tens places goes up by 1. Examples: Number Rounded
1628     1630
1625     1625
1621     1620
1610     1610


Hi Chuck

How about this:

use strict;
use warnings;

for my $n ( qw/1628 1625 1621 1610/ ) {
 print $n, '     ', round5($n), "\n";
}

sub round5 {
 my $n = shift() + 2;
 $n - $n % 5;
}

**OUTPUT**

1628     1630
1625     1625
1621     1620
1610     1610


HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to