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:
- Added 105.25 from $105.25 and set it to 105.25
- Added 105.25 from $105.25 and set it to 210.5
- Added 105.25 from $105.25 and set it to 315.75
- ....many rows later...
- Added 68.90 from $68.90 and set it to 6257.65
- Added 33.40 from $33.40 and set it to 6291.04999999999
- Added 100.90 from $100.90 and set it to 6391.94999999999
- ..many rows later...
- Added 153.70 from $153.70 and set it to 9897.64999999999
- Added 102.70 from $102.70 and set it to 10000.35
- Added 128.80 from $128.80 and set it to 10129.15
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.