Hello, The function sprintf does the rounding automatically. You don't need to add the 0.005.

From the sprintf manual:

f,F  The  double  argument  is  rounded and 
converted to decimal notation in the style -ddd.ddd, 
where the number  of digits after the decimal-point 
character is equal to the precision  specification.  
Doing a small test reveals the same behavior in perl:
#!/usr/bin/perl -w
print `cat $0`;
for $i (1..10){
	my $num = 0;
	for(1..9800*$i){
		$num += 0.0001/$i;
	}
	print "$num = ";
	$num = sprintf("%.4f", $num);
	print "$num\n";
}
0.979999999999908 = 0.9800
0.9799999999999 = 0.9800
0.979999999999902 = 0.9800
0.980000000000962 = 0.9800
0.980000000000699 = 0.9800
0.979999999999897 = 0.9800
0.980000000000605 = 0.9800
0.979999999999383 = 0.9800
0.979999999998648 = 0.9800
0.979999999998175 = 0.9800
Aziz,,,

In reply to Re: Re: Filthy Floats by abstracts
in thread Filthy Floats by THuG

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.