Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

There are actually standards regarding how rounding should be done, e.g. http://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules (which is probably not universally followed) and ISO 717-1:1996. On the other hand, since floating point numbers are not real numbers (they're a subset of rational numbers), there will be times when sprintf will round the value it's given correctly, but the value that it gets is not correct, depending on how well the floating point library is written (some are much better than others) and the details of the computations being done

I've had to deal with hand-rolled rounding solutions (so that rounded numbers would add up to an integral value). You may have to roll your own rounding subroutine if you've got specific requirements.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc


In reply to Re: F***ing sprintf rounding - how does it work? by swampyankee
in thread F***ing sprintf rounding - how does it work? by ribasushi

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2014-12-18 01:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (41 votes), past polls