A strange thing has cropped up in my code. Here's the relevant snippet, with some debugging added:

my $val=0; for (@rows) { if (/([\d.]+)/) { $val += $1; warn "<LI>Added $1 from $_ and set it to $val\n"; } }

The row values are mostly dollar-sign formatted, as you can see from the sample output. It gets funky at one particular spot:

I can guess that perl is setting the match in the regular expression as a float, because of the decimal place, but what cause it to suddenly decide that 6257.65 plus 33.40 is 6291.04999999999??

Any workarounds welcome, too, although the actual code is not as simple as the example above.


In reply to Unwanted implicit conversion to float by turnstep

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.