Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 '>='
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?
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 browsing the Monastery: (13)
As of 2015-07-08 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls