The floating-point parts of s?printf() are not implemented directly in perl itself, but handed off to the system library's sprintf() function. As a result, you are at the mercy of any bugs (in rounding or anything else) in the particular version of the system library you (or your customer) are using.

This is the only part of s?printf() handed off in that way in modern perls. In general, I tend to avoid use of floating-point numbers as far as possible in any application for which precise results are important - often you can model the values you need with integers or rationals, and the Math::Big* family of modules can also help out.

Hugo

In reply to Re: Re: rounding to nearest integer by hv
in thread rounding to nearest integer by dsm

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.