I dunno what to tell you, except you're dealing with floats... deal with ints instead ... (I have no insight, only code, well a little insight - perl has internal ways of distinguishing numbers from strings .... (s)printf are c functions, do stuff similar to (un)pack in fsking with the numbers ... that kinda it, vague ain't it )
#!/usr/bin/perl my $one = 7 + (2 - (0.5 * 9)); my $two = 7 + (2 - (0.5 * 9)); my $thr = 7 + (5 - (0.5 * 9)); for($one,$two,$thr) { printf "no_ROUND(%s) yes_ROUND(%d) foy_FLOAT(%f) foy_ROUND(%.0f)\n\n", $_,$_,$_,$_; =head2 UPDATE: uncomment this to add to the mistery print "pack i ".unpack('i*', pack('i*', $_))."\n"; print "pack l ".unpack('l*', pack('l*', $_))."\n"; print "pack f ".unpack('f*', pack('f*', $_))."\n"; print "pack d ".unpack('d*', pack('d*', $_))."\n"; =cut and don't forget cut# } __END__ =pod C:\>perl round.txt no_ROUND(4.5) yes_ROUND(4) foy_FLOAT(4.500000) foy_ROUND(5) no_ROUND(4.5) yes_ROUND(4) foy_FLOAT(4.500000) foy_ROUND(5) no_ROUND(7.5) yes_ROUND(7) foy_FLOAT(7.500000) foy_ROUND(8) =head1 that is an interesting way to get an int %% a percent sign %c a character with the given number %s a string %d a signed integer, in decimal %u an unsigned integer, in decimal %o an unsigned integer, in octal %x an unsigned integer, in hexadecimal %e a floating-point number, in scientific notation %f a floating-point number, in fixed decimal notation %g a floating-point number, in %e or %f notation =cut
update: guha brings up a good point, ints/floats will still vary from system 2 system

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac) Re: Rounding With sprintf anomaly? by crazyinsomniac
in thread Rounding With sprintf anomaly? by oakbox

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.