Wayne Simmons wrote:
> From: Wayne Simmons
> > 
> > my $x = .0006;
> > my $y = $x * 10000;
> > print $y , "\n";
> > print sprintf("%04d\n",$y);
> > print int($y), "\n";
> > __END__
> 
> From: Christopher Hahn [mailto:[EMAIL PROTECTED]
> > 
> > Int returns the integer portion --> it truncates!
> 
> 
> Great, thanks for filling me in! So 6 truncates to 5 in perl?!? :-0

No, 5.9999999999999991118215803 truncates to 5 in most any language.

The problem is that floating point calculations are always
approximate in computers.

This may make more sense:

    my $x = .0006;
    my $y = $x * 10000;
    print "Number looks like this: $y\n";
    printf "But it is really this: %0.25f\n", $y;
    printf "And it truncates to this: %d\n",$y;

Output:

    Number looks like this: 6
    But it is really this: 5.9999999999999991118215803
    And it truncates to this: 5

-- 
Bowie
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to