in reply to Re: unexpected result using '>='
in thread unexpected result using '>='

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.

Replies are listed 'Best First'.
Re^3: unexpected result using '>='
by ysth (Canon) on Aug 16, 2006 at 23:47 UTC
    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
Re^3: unexpected result using '>='
by GrandFather (Saint) on Aug 16, 2006 at 23:27 UTC

    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!)