<?xml version="1.0" encoding="windows-1252"?>
<node id="1000734" title="Best way to round a number." created="2012-10-24 19:07:09" updated="2012-10-24 19:07:09">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
Hi Monks!&lt;br&gt;

I need to round a number to its nearest 5 I would say, like;
if I have 33 it should give me 30, if its 3 I should get 5, if its 36 I should get 40, if its 5 it should be 5, if its 6 it should be 10 and so on. This is what I have, see the code below. Is there a better way of doing this?&lt;br&gt;
&lt;code&gt;
use strict;
use warnings;
use POSIX qw(ceil);
use POSIX qw(floor);

my $num = 11;
   $num =~ m/\d*(\d{1})/;

my $check = $1;

if($check &lt; 5) {

  $num = ceil($num/5)*5;
  
}else {

  $num = floor($num/5)*5;
}

print "\n $num \n\n";
&lt;/code&gt;
&lt;br&gt;
Thanks for looking!</field>
<field name="reputation">
9</field>
</data>
</node>
