title: Why does Perl's sprintf not round floating point numbers correctly?
body: <p>I was out looking for the rounding convention used by Perl's built-in function <a href="http://perldoc.perl.org/functions/sprintf.html" rel="nofollow noreferrer">sprintf</a>.</p>
  
  <p>I was thinking that it does a normal rounding (e.g. ROUND_HALF_UP as in <a href="http://www.j2ee.me/javase/6/docs/api/java/math/RoundingMode.html" rel="nofollow noreferrer">Java's rounding mode convention</a>), but digging further proved this to be wrong:</p>
  
  <pre><code>&gt; /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 0.335
  0.34
  &gt; /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 1.335
  1.33
  </code></pre>