+ # Remember the amount's sign but calculate in positive values only.
+ my $sign = $amount <=> 0;
+ $amount = abs $amount;
+
+ # Shift the amount left by $places+1 decimal places and truncate it
+ # to integer. Then to the integer equivalent of rounding to the next
+ # multiple of 10: first add half of it (5). Then truncate it back to
+ # the lower multiple of 10 by subtracting $amount modulo 10.
+ my $shift = 10 ** ($places + 1);
+ $amount = int($amount * $shift) + 5;
+ $amount -= $amount % 10;