06-25-2003, 10:43 PM
Here's a little algorithm that I derived.
Given a positive integer number N, compute the next multiple of X:
Result to M.
defint a-z
M = int((N+X)/X)*X
Note: "next" multiple means that if you're already at a multiple, you move up to the next multiple. Example: if N=5 and X=5, the result will be 10.
If you got that, then make a slight change to the algorithm to compute the "nearest" multiple. Example: if n=5 and x=5, the result is 5 because it is the nearest (you're already there). This is like rounding --- if it's already rounded, then that's the answer.
*****
Given a positive integer number N, compute the next multiple of X:
Result to M.
defint a-z
M = int((N+X)/X)*X
Note: "next" multiple means that if you're already at a multiple, you move up to the next multiple. Example: if N=5 and X=5, the result will be 10.
If you got that, then make a slight change to the algorithm to compute the "nearest" multiple. Example: if n=5 and x=5, the result is 5 because it is the nearest (you're already there). This is like rounding --- if it's already rounded, then that's the answer.
*****