I had written a well thought out reply to this, but then by browser crashed, so I'll just provide some points on why this script fails:

  • First of all, it's syntactically invalid (this, I assume, is just a type): you provide a " before ($a%100), I assume that isn't meant to be there. Also, you need to place parentheses around your print call so all of the items you want to send go to print.
  • Second, It doesn't account for the fact that the computer cannot store the floating point numbers accurately.
  • Third, it produces output like this: (when the typos are corrected)
    1.23.23 4.345.34 5.523.52
    You see, you print ($a/100), but if that is a decimal, then it will print (decimal and all!), and then the added decimal will print, not what you want.
  • Last, it doesn't round. The middle number should read 4.35 (after being rounded), but your code (ignoring the extra decimal and just reading from the last), makes it 4.34.

    The 15 year old, freshman programmer,
    Stephen Rawls

    In reply to Re: Re: Re: strange rounding behaviour by srawls
    in thread strange rounding behaviour by Anonymous Monk

    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.