It has already been said, but it bears repeating since so many people get caught out. There is no such thing as floating point with "reasonably uncomplicated values". Just because a number looks sane in base 10 doesn't mean it's a rational number in binary.

You have a few choices about how to deal with this issue. It does depend on how important this is to you, and what you are trying to accomplish. People writing software for financial institutions will do different things from students just playing with lab results.


Update: Hi ikegami, I meant "rational" loosely as a synonym for sane just to avoid repeating myself. I shouldn't have used a word with a well-known mathematical meaning. :-)

In reply to Re: 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals) by virtualsue
in thread 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals) by jplindstrom

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.