sub roundoff
{
my $num = shift;
my $roundto = shift || 1;
return int($num/$roundto+0.5)*$roundto;
}
foreach my $i (0.6, 1.2, 38.4, 88.6, 92.5)
{
printf "%5.1f ",$i;
foreach my $j (1, 10, 100)
{
printf "%2d ", roundoff($i,$j);
}
print "\n";
}
####
use POSIX qw(ceil);
sub roundup
{
my $num = shift;
my $roundto = shift || 1;
return int(ceil($num/$roundto))*$roundto;
}
####
sub max
{
return $_[0] > $_[1] ? $_[0] : $_[1];
}
sub rightscale
{
my $num = shift;
return 10 ** max(int(log(abs($num))/log(10))-1,1);
}