in reply to rounding to nearest integer
perldoc -q round gives us this out of perlfaq4 =). It shows you were on one of the right tracks with printf().
Does Perl have a round() function? What about ceil() and floor()? Trig functions?
Remember that int() merely truncates toward 0. For rounding to a certain number of digits, sprintf() or printf() is usually the easiest route.The POSIX module (part of the standard Perl distribution) implements ceil(), floor(), and a number of other mathematical and trigonometric functions.printf("%.3f", 3.1415926535); # prints 3.142
use POSIX; $ceil = ceil(3.5); # 4 $floor = floor(3.5); # 3
--
Allolex
|
|---|