in reply to Re: Rounding of a number...
in thread Rounding of a number...
In case anyone is wondering why floor() and not int(), it depends on your definition of "rounding" -- int() always rounds towards zero. floor() always rounds down to the next integer that is less than or equal to the number being rounded. This difference is important for negative numbers. E.g.:
$ perl -le 'print int(5.45)' 5 $ perl -le 'print int(-5.45)' -5 $ perl -MPOSIX -le 'print floor(5.45)' 5 $ perl -MPOSIX -le 'print floor(-5.45)' -6
-xdg
Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.
|
|---|