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

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.


Comment on Re^2: unexpected result using '>='
Re^3: unexpected result using '>='
by GrandFather (Cardinal) 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
      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!)
      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".
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://567790]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-10-26 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls