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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Today I stumbled across the following piece of code and I'm still wondering why the condition is not met:
my $a = 36.8; my $b = 36.6; if( $a >= ( $b + 0.2 ) ) { print "true\n"; }
=> returns nothing (Why's that? 36.8 equals 36.6 + 0.2)

Whereas the condition becomes true if I change the values a little bit:
my $a = 6.8; my $b = 6.6; if( $a >= ( $b + 0.2 ) ) { print "true\n"; }
=> returns "true" (that's what i expected)

I feel a little bit stupid asking this question and have the strange feeling that my mind is playing a trick on me here because I've been doing perl stuff since many years now. Must have got something to do with floating point values and the "greater or equal than" operator, I guess.

Could somebody please tell me why the above code fragments work like they do and not how I think they should work?

Thanx!

In reply to float values and operators by soulchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found