in reply to weird print behavior

"perldoc -q .999999" will explain this better than I could. You're experiencing a non-Perl-specific problem with finite precision for floating point numbers.

Using printf "%.2f\n", $i will give you what you expect.

Replies are listed 'Best First'.
Re: Re: weird print behavior
by anjiro (Beadle) on Dec 22, 2003 at 22:54 UTC
    Well, that does make a certain amount of sense. However, why does this only show up sometimes? In the loop I get the problem, but when I do
    printf("%.14f\n", (6.8 + .1));
    I get 6.90000000000000.