Rounding Question
Jacob Kaplan-Moss
jacobkm at cats.ucsc.edu
Wed Feb 21 13:27:58 EST 2001
In article <96vudj02hnf at news1.newsguy.com>, "Alex Martelli"
<aleaxit at yahoo.com> wrote:
[snip a whole bunch of great ideas...]
Thanks so much for the great discussion; although this is really a
trivial part of what I'm doing, it's nice to be able to do it right...
In the end, I decided that:
> def nextHigherOrEqualMultiple(depth, N):
> "compute the least multiple of N >= depth"
> return int((depth+N-1)/N) * N
>
> with
>
> tableDepth = nextHigherOrEqualMultiple(depth, 10)
is what I'm going to use; I really only need to make this calculation
once, so a long function name really isn't a problem, and although I'm
writing for NAUI tables now, I know that certain other tables use
increments of 5 feet, so it makes sense to have a generic function
available.
Thanks once again,
Jacob
More information about the Python-list
mailing list