Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: unexpected result using '>='

by jonnyfolk (Vicar)
on Aug 16, 2006 at 23:18 UTC ( #567790=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://567790]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-06-18 04:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.