RobertCraven has asked for the wisdom of the Perl Monks concerning the following question:
Depending on the initial value of $i, it adds 0.09 at a different point.#!/usr/bin/perl use warnings; use strict; for (my $i = 0 ; $i < 9 ; $i += 0.1){ print "$i\n"; } OUTPUT (truncated): (...) 4.9 5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.99999999999999 6.09999999999999 6.19999999999999 6.29999999999999 6.39999999999999 6.49999999999999 (...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: for loop with float
by ikegami (Patriarch) on Jul 24, 2008 at 22:35 UTC | |
|
Re: for loop with float
by FunkyMonk (Bishop) on Jul 24, 2008 at 22:46 UTC | |
|
Re: for loop with float
by BrowserUk (Patriarch) on Jul 24, 2008 at 22:47 UTC | |
by RobertCraven (Sexton) on Jul 24, 2008 at 23:10 UTC | |
|
Re: for loop with float
by gloryhack (Deacon) on Jul 24, 2008 at 22:47 UTC | |
|
Re: for loop with float
by swampyankee (Parson) on Jul 25, 2008 at 04:09 UTC | |
|
Re: for loop with float
by jethro (Monsignor) on Jul 24, 2008 at 23:24 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2008 at 00:38 UTC | |
by jethro (Monsignor) on Jul 25, 2008 at 03:31 UTC |