in reply to Rounding to the nearest 50

First of all, you are not looking for the nearest value. What you need is a customised ceil (see perldoc POSIX).

In such cases, where you want to look for the "nearest but not smaller then" and your step is not 1, but X (X = 50 in your case), you can do the following:

use POSIX; sub ceilX ($$); print "$_ -> ", ceilX($_, 50), "\n" for (145..154); sub ceilX ($$) { my $number = shift; my $x = shift; return POSIX::ceil($number / $x) * $x; }


with the result

145 -> 150 146 -> 150 147 -> 150 148 -> 150 149 -> 150 150 -> 150 151 -> 200 152 -> 200 153 -> 200 154 -> 200


Edit: Sorry, I was interrupted while writing this answer, when I started writing, there was no comparable posted.