2.2 浮動小数点を丸める

# 小数点第3位で丸める
$rounded  = sprintf("%.2f", $unrounded);

# int, floor, ceil関数を使う
use POSIX qw(floor, ceil);
printf "%8s %8s %8s %8s %8s\n",
  qw(number even zero down up);
for $n (-6 .. +6) {
  $n += 0.5;
  printf "%8g %8.0f %8s %8s %8s\n",
             $n, $n, int($n), floor($n), ceil($n);
}