Help for this page

Select Code to Download


  1. or download this
    sub round {
      my $n = shift;
      int($n + .5 * ($n < 0 ? -1 : 1));
    }
    
  2. or download this
    sub round {
      my ($n, $p) = @_;
      $p ||= 0;  # default to integer rounding
      int($n * 10**$p + .5 * ($n < 0 ? -1 : 1)) / 10**$p;
    }