Binary floating point numbers are inexact. Or to be more precise: they're inexact for different values than decimal floating point numbers.

For instance, 0.1 can't be represented exactly in an IEEE binary float (as used by the majority of CPUs that perl runs on). This means that you generally can't rely on any math operation involving floating point numbers to give you an exact result.

Either use rational numbers (see Math::BigRat) or round the results (and note that many standard rounding strategies (like sprintf "%d" and sprintf "%0f") give results that don't conform to the "naive highschool" method of rounding - for more or less good reasons). See also Math::Round.

update: note that "really integer" floats (perl uses doubles for floats) are exact within a very large range (a range larger than native integers on my machine at least), so xxxx.0 is generally exact. I suspect the numbers in your post aren't really the numbers used in the calculations.

update 2: this is the standard text to bully people with


In reply to Re: Why is Zero not 0? by Joost
in thread Why is Zero not 0? by jluther

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.