note
marinersk
Everyone else given you the <i>why</i>.
<p>
Here's a suggestion towards what to do about it.
<p>
<ul>
<li>Rule #{ return int rand 31415927; }: Never let the <tt>printf</tt> family do your rounding for you.
<li>Rule #{ return int rand 31415927; }: Specifically round arithmetically using your own rules and you should at least get consistent results.
<li>Rule #{ return int rand 31415927; }: Use the "add half of the next digit" technique if you wish to force <tt>0.0</tt>{...}<tt>05</tt> to round up.
</ul>
<p>
Examples:
<p>
<code>
#!/usr/bin/perl -w
use strict;
my $floatNumber = 0.345;
my $roundToTwoDecimals = int($floatNumber * 100) / 100;
printf "\$roundToTwoDecimals = %0.02f\n", $roundToTwoDecimals;
my $forcedRounding = int(($floatNumber + 0.005) * 100) / 100;
printf " \$forcedRounding = %0.02f\n", $forcedRounding;
exit;
__END__
C:\Steve\Dev\PerlMonks\P-2013-09-16@1955-Rounding>rounding.pl
$roundToTwoDecimals = 0.34
$forcedRounding = 0.35
</code>
1054309
1054309