in reply to Rounding to the nearest 50

for my $n (148..153) { print $n + 50 - $n % 50, "\n"; }
for my $n (148..153) { print $n, '=>', $n + 49 - ($n - 1) % 50, "\n"; }

Where  $n + 49 - ($n - 1) % 50 computes the rounding up to the nearest 50.

Update: Modified the fomula so that 150 will not be rounded to 200.

Replies are listed 'Best First'.
Re: Re: Rounding to the nearest 50
by esskar (Deacon) on Mar 01, 2004 at 14:22 UTC
    your code
    for my $n (148..153) { print $n + 50 - $n % 50, "\n"; }
    does the same error as borisz' original post...

    Update:
    now it's better! :p