# Rounders.pm # # ======== package Rounders; # ======== use strict; use warnings; use Exporter; our @ISA = qw{Exporter}; our @EXPORT = qw{rndZero rndPlaces}; use POSIX qw(ceil floor pow); # ------- sub rndZero # ------- { my $val = shift; my $rounded = $val < 0 ? POSIX::ceil($val - 0.5) : POSIX::floor($val + 0.5); return $rounded; } # --------- sub rndPlaces # --------- { my($val, $places) = @_; my $rounded = rndZero($val * POSIX::pow(10.0, $places)) / POSIX::pow(10.0, $places); return $rounded; } 1;