in reply to Rounding of a number...

The politically and mathematically correct way to do this is to use POSIX floor().
use POSIX; my $y=523.4; printf('%7.2f',floor($y*100/52)/100); --Output--- 10.06
The VALLUE that prints as 10.06 is 10.06538.

    ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Replies are listed 'Best First'.
Re^2: Rounding of a number...
by xdg (Monsignor) on Dec 27, 2004 at 14:45 UTC

    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.