in reply to Re: Rounding With sprintf anomaly?
in thread Rounding With sprintf anomaly?

Intel chip, Linux (cobalt's hacked Redhat version), and Perl 5.6.1. POSIX 'floor' and 'ceiling' are mentioned in a couple of posts elsewhere on perlmonks. I'll look into those.

I think the suggestion that the 5 isn't really a '5' holds the most water. There are actually about 28 separate calculations being performed in that section and it is only in THAT PARTICULAR section that the round doesn't perform as expected.

Okay, I'm happy again. I just wanted an explanation for the (apparently) freaky behaviour.

-oakbox

Replies are listed 'Best First'.
Re: Re: Re: Rounding With sprintf anomaly?
by riffraff (Pilgrim) on Feb 27, 2002 at 14:39 UTC
    I think if you want a proper rounding, you do this:

    $x=int($num+0.5);

    This gets rid of all those oddities, like a number looking like 5.5, but actually being 4.9999999....

    Sorry, typo, should be 5.499999...