in reply to Reduce from 2 to 0.1.

How about this then?
#!/usr/local/bin/perl5 -w use strict; for (my $i = 20 ; $i >= 1 ; $i -= 1){ printf "%f\n", $i/10; }
It produces nice output:
2.000000 1.900000 1.800000 1.700000 1.600000 1.500000 1.400000 1.300000 1.200000 1.100000 1.000000 0.900000 0.800000 0.700000 0.600000 0.500000 0.400000 0.300000 0.200000 0.100000
But it's a rather horrible solution, really... :-)

Replies are listed 'Best First'.
Re: Re: Reduce from 2 to 0.1.
by riffraff (Pilgrim) on Apr 10, 2001 at 20:21 UTC
    Whenever I needed decimals, to a specific number of places (and not a variable number of places), then I used an int scaled up the appropriate amount,then used a printf("%d.%d",i/100,i%100); (or whatever the scale was) to print.

    This avoided FPU use (way back when when FP was really, really slow), and avoided rounding errors.

    Of course, if you have a variable amount of decimal places, this might not be feasible.

    -lsd