in reply to non-integer increments

Once again I learn something from someone else's question. Now I have a question of my own. Is there some way to easily deal with this problem?

Replies are listed 'Best First'.
Re^2: non-integer increments
by ikegami (Patriarch) on Dec 02, 2004 at 16:03 UTC

    Yes, use an integer for the counter, and derive the floating point number from it. Integers are represented accurately and they don't accumulate error (unless they grow beyond a certain size).

    my $i=0; print($i, "\n"); while ($i < 10){ my $n = ++$i / 10; print($n, "\n"); }

    Update: oops, typo fixed.

      for (0..10) { print $n/10,"\n"; }
      ---
      demerphq

      just a small remark
      your probably meant
          $n = $i / 10;
      else you print out a few 0s
      si_lence