sub round { my ($self, $number, $precision) = ...; ... my $multiplier = (10 ** $precision); my $result = abs($number); my $product = $result * $multiplier; ... # We need to add 1e-14 to avoid some rounding errors due to the # way floating point numbers work - see string-eq test in t/round.t $result = int($product + .5 + 1e-14) / $multiplier; ... return $result; }