in reply to unexpected result using '>='

Adding

print "\n", $in_view - $period, "\n";

after your current print line tells a story:

Content-type: text/html 239.6 ::239.6<br> 2.8421709430404e-014 0 ::239.6<br> 239.6

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: unexpected result using '>='
by jonnyfolk (Vicar) on Aug 16, 2006 at 23:18 UTC

    I see, thanks

    How can I force the calculation to calculate to 2 decimal places only - I've tried sprintf but the result is still in discrepancy.

      You mean something like $period - $in_view > .01 instead of $period >= $in_view?

      By the way, it's just a matter of time till you burn yourself by misinterpreting the sense of an unless. Some people recommend never using unless; I think it's ok so long as the expression is a single simple variable.

        I'd be inclined to use abs ($period - $in_view) > 0.01.

        /me slaps forehead. That's good for not equal, but ain't so good for >=! (thanks ysth).


        DWIM is Perl's answer to Gödel

      You could use ge rather than >= which stringises the values.

      Your original code then prints:

      Content-type: text/html 119.8 ::239.6<br>

      DWIM is Perl's answer to Gödel
        But you almost never want to use ge for comparing numbers. For example,
        my $x = 3; my $y = 20; if ($x ge $y) { print "$x ge $y\n"; }
        will print "3 ge 20".
        Many thanks for that - much closer to what I was expecting to see! I shall read up on the difference between >= and ge in the morning (it's now 1:30am CET!)