In cb, you indicated that the general problem is to do a Banker's Round, where /\d5/ is rounded to the even digit. I think you want to work with the string representation of the number for this, so that machine numbers don't interfere with the rules.

# handle 5 in the thousandth's place with nothing or zeros following $pete =~ s/( # substitute, start capture $1 \d* # none or more digits \. # a decimal point \d # tenths digit (\d) # capture hundredths digit as $2 ) # end capture $1 50*$ # digit 5 followed by none or more 0's to the end /1&$2 ? $1+.01 : $1/xe; # then do as you had $rooker = sprintf "%.2f", $pete;
By handling the special case as a string before the numeric round, we avoid binary-meets-decimal conflicts.

After Compline,
Zaxo


In reply to Re: A simple rounding question, but can't get it! by Zaxo
in thread A simple rounding question, but can't get it! by DippinPete

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.