http://qs321.pair.com?node_id=11123116

geoperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I came across with a strange result when I'm using int() function. For example,

my $x1 = (1.15*170)+0.50; my $x2 = int($x1); print "Number is: $x1, Integer part is: $x2";

It prints "Number is: 196, Integer part is: 195", but I would expect $x2 to be 196

But when I am using different numbers I am getting the correct results. For example,

my $x1 = (1.15*150)+0.50; my $x2 = int($x1); print "\nNumber is: $x1, Integer part is: $x2";
my $x1 = (1.15*30)+0.50; my $x2 = int($x1); print "\nNumber is: $x1, Integer part is: $x2";

Can anybody guess what goes wrong with the first one, what goes wrong when I'm using the number 170? At least, I would expect either all results be correct or all results be wrong, but not just one be wrong.

Using int(sprintf("%.2f",$x1)) fixes the error but this is not the issue.