For some reason I was under the impression that the int function was doing rounding rather than truncating, so took a quick look at perldoc -f int, which mentioned that you should use POSIX::floor() rather than int. And sure enough, the code snippet above provides what I'd consider to be incorrect results for negative values. The OP doesn't mention if the input values will ever be negative, but consider the following:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
my $num = -1.2;
my $rounded_pos = (POSIX::floor($num*2))/2;
my $rounded_int = (int $num*2)/2;
printf "Rounded is %.1f for %f using POSIX\n", $rounded_pos, $num;
printf "Rounded is %.1f for %f using int\n", $rounded_int, $num;
__END__
Output:
Rounded is -1.5 for -1.200000 using POSIX
Rounded is -1.0 for -1.200000 using int
Simple change, and seems to be more robust. (Added: Although I may just be misinterpreting "rounding down" -- I think "down" is "in the negative direction" as opposed to "closer to zero". Hmm.)