use strict; use warnings; for ( my $foo = -2; $foo <= 2; $foo += 0.2 ) { my $bar = int( $foo < 0 ? $foo - 0.5 : $foo + 0.5 ); print "$foo = $bar\n"; }