in reply to Best way to make sure a number is an even multiple of another?

M goes into N int( N/M ) times, with a remainder of M%N.

So, M * (1 + int( N/M )) will be the smallest multiple of M greater then N.

--
TTTATCGGTCGTTATATAGATGTTTGCA

  • Comment on Re: Best way to make sure a number is an even multiple of another?

Replies are listed 'Best First'.
Re^2: Best way to make sure a number is an even multiple of another?
by Roy Johnson (Monsignor) on Oct 21, 2004 at 17:00 UTC
    The trick is that what the OP wanted was greater than or equal to, without doing an if (or equivalent). Here's one way to modify your suggestion:
    $m*(($n%$m > 0) + int($n/$m));

    Caution: Contents may have been coded under pressure.