in reply to Round down to '.5' or '.0'

There's an easy method:
sub round_to_halves { return 0.5 * (int(2*$_[0])); } my $num = 1.6; print round_to_halves($num), "\n";

Replies are listed 'Best First'.
Re^2: Round down to '.5' or '.0'
by gamache (Friar) on Oct 24, 2007 at 18:43 UTC
    Hell, why stop there?
    sub round_to_nths { my ($num, $n) = @_; (int $num*$n)/$n }
    Now you and me can reuse our rounding code all day, giggling as the split-based solution chokes on a well-placed $num = '123E-1'...