sub consistentlyRound { my( $w ) = @_; my $p = int( ($w+0.005)*100 ); return $p/100; } my $x = 0.015; my $y = 0.0001; $y += 0.0001 for 1..149; print "x=$x y=$y\n"; printf "x~%.2f y~%.2f (stupid printf rounding)\n", $x, $y; $x = consistentlyRound( $x ); $y = consistentlyRound( $y ); print "x~$x y~$y (consistent arithmetic rounding)\n"; __END__ x=0.015 y=0.015 x~0.01 y~0.01 (stupid printf rounding) x~0.02 y~0.01 (consistent arithmetic rounding)