I came across a very odd situation and was hoping a fellow monk could clarify as why it happened/
I have a small snippet of code that compares numbers. It has worked fine for some time without problem until -2.97 came along.

I try to compare two numbers. The one way works as expected but the other does not.
my $batch_total = 297; my $batch_sign_indicator = '-'; my $close_response; $close_response->{batch_net_amount} = -2.97; #this code doesn't work. it returns false my $test_batch_amount = ($batch_sign_indicator eq '-') ? ((0 - $batch_ +total) / 100) : ($batch_total / 100); if($test_batch_amount == $close_response->{batch_net_amount}){ print "good!!! $test_batch_amount == $close_response->{batch_net_a +mount}"; } else{ print "no good $test_batch_amount == $close_response->{batch_net_a +mount}"; } ####THIS CODE DOES WORK AS EXPECTED AND RETURNS TRUE my $test_batch_amount = ($batch_sign_indicator eq '-') ? ((0 - $batch_ +total)) : ($batch_total); if($test_batch_amount == ($close_response->{batch_net_amount}*100)){ print "good!!! $test_batch_amount == $close_response->{batch_net_am +ount}"; } else{ print "no good $test_batch_amount == $close_response->{batch_net_am +ount}"; }
Why?? Thanks again.

In reply to inequality of appearing same number by bear0053

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.