N
Nithy
Hi,
Can anyone help me in floating point round off error. I have the
code as shown below.
#!/usr/bin/perl
#This program increments the value from x.1 to x.9
$count = 0;
$out = 0;
while($out == 0)
{
print ("count = ",$count,"\n");
$count=$count + 0.1;
if ($count == 0.9)
{
$out=1;
}
If I run this code, it doesn't terminate when $count reach 0.9. Its
keep on increasing. And after 5.9 its showing 5.99999999999999 & so
on..
But If I limits it within 0.8(if $count = 0.1 - 0.7), it gives the
proper output. Why is it so?
Please let me know your suggestion.
Thanks in advance.
Regards,
Nithy
Can anyone help me in floating point round off error. I have the
code as shown below.
#!/usr/bin/perl
#This program increments the value from x.1 to x.9
$count = 0;
$out = 0;
while($out == 0)
{
print ("count = ",$count,"\n");
$count=$count + 0.1;
if ($count == 0.9)
{
$out=1;
}
If I run this code, it doesn't terminate when $count reach 0.9. Its
keep on increasing. And after 5.9 its showing 5.99999999999999 & so
on..
But If I limits it within 0.8(if $count = 0.1 - 0.7), it gives the
proper output. Why is it so?
Please let me know your suggestion.
Thanks in advance.
Regards,
Nithy