Given a positive number N, compute R, the NEXT multiple of x.

Example #1: Given 47, compute the next multiple of 5 after 47: 50.

Example #2: Given 50, compute the next multiple of 5, after 50: 55.

Three ways to do it:

DEFINT A-Z

r = 47

x = 5

r = (1 + n \ x) * x: PRINT r

r = n - n MOD x + x: PRINT r

r = ((n + x) \ x) * x: PRINT r

However, the following is the original algorithm that I developed, and the only one that I have tested.

R = int((N+X)/X)*X

Moneo 02Nov06

Credit: Moneo, Agamemnus.

NextMultiple - page last edited 2006-11-02 19:34:11 by 189.141.50.135 (home) (edit)

Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster

Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster