in reply to Rounding numbers

print int($average * 100)/100, "\n";

Replies are listed 'Best First'.
Re^2: Rounding numbers
by Laurent_R (Canon) on Mar 25, 2014 at 19:48 UTC
    I am sorry, but using the int function does not give you proper rounding.
    $ perl -e 'print int(.678*100)/100;' 0.67
    The result for .678 should be 0,68, not 0.67. The int can certainly be used for building a rounding subroutine, but not with the code presented, it is quite more complicated.
      I understand it is not "proper" rounding. I had the feeling the poster just wanted a quick way to "truncate" the answer to 2 decimal places when printing to an output file.