int(x+.5) rounds positive values ββto the nearest integer. Rounding is harder.
To round to zero:
int($x)
In the solutions below, include the following statement:
use POSIX;
To round: POSIX::floor($x)
To round: POSIX::ceil($x)
To round from zero: POSIX::floor($x) - int($x) + POSIX::ceil($x)
To round to the nearest integer: POSIX::floor($x+.5)
Note that int($x+.5) does not work well for negative values. int(-2.1+.5) is equal to int(-1.6) , which is -1.
Steve Schaefer Dec 14 '09 at 20:07 2009-12-14 20:07
source share