Given a positive number N, compute R, the NEAREST multiple of X.

Note: Nearest multiple means that if N is already a multiple of X, don't move up to next multiple. This is kind of like rounding; e.g., round to $47 to the nearest $5. If already a multiple of $5, leave it alone.

example #1: Given 47, compute the nearest multiple of 5, which is 50.

example #2: Given 50, compute the nearest multiple of 5, which is 50.

DEFINT A-Z

n = 47

x = 5

rem ... r = ((n + x + 1) \ x) * x

R = int((N+X-1)/X)*X 'Corrected by Moneo 02Nov06

PRINT r

Credits: Moneo, Agamemnus.

NearestMultiple - page last edited 2006-11-02 19:12:54 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