anjiro has asked for the wisdom of the Perl Monks concerning the following question:
Produces:for(my $i = 5.5; $i < 7; $i += .1) { if($i > 6.8) { printf "%f\n", $i; print "$i\n"; } }
But if I change the %f in the printf to %.14f, I get 6.99999999999999 instead of 7.0000. What gives? Seems like I shouldn't ever get 6.9999 when adding .1 to 6.9...6.900000 6.9 7.000000 6.99999999999999
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: weird print behavior
by kesterkester (Hermit) on Dec 22, 2003 at 22:09 UTC | |
by anjiro (Beadle) on Dec 22, 2003 at 22:54 UTC | |
|
Re: weird print behavior
by Joost (Canon) on Dec 22, 2003 at 22:55 UTC | |
|
Re: weird print behavior
by Zed_Lopez (Chaplain) on Dec 22, 2003 at 23:17 UTC | |
|
Re: weird print behavior
by SavannahLion (Pilgrim) on Dec 23, 2003 at 01:02 UTC | |
by talexb (Chancellor) on Dec 23, 2003 at 04:29 UTC | |
|
Re: weird print behavior
by Ninthwave (Chaplain) on Dec 23, 2003 at 09:50 UTC |