Dear monks,
I have a script that make a simple math addition.
The strange thing is that it adds some floating point numbers.
The script:
$count = 895.3; while ($count <= 900) { $count += 0.01; print "$count\n"; } The output: 895.31 895.32 895.33 895.34 895.35 895.36 895.37 895.38 895.39 895.4 895.41 895.42 895.43 895.44 895.45 895.46 895.47 895.48 895.49 895.5 895.51 895.52 895.53 895.54 895.55 895.56 895.57 895.58 895.59 895.6 895.61 895.62 895.63 895.64 895.65 895.66 895.67 895.68 895.69 895.7 895.71 895.72 895.73 895.74 895.75 895.76 895.77 895.78 895.79 895.8 895.809999999999 895.819999999999 895.829999999999 895.839999999999 895.849999999999 895.859999999999 895.869999999999 895.879999999999 895.889999999999 895.899999999999 895.909999999999 895.919999999999 895.929999999999 895.939999999999 895.949999999999 895.959999999999 895.969999999999
Your help please. Regards.

In reply to perl floating number addition by adismaug

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.