Rounding Question

Jacob Kaplan-Moss jacobkm at cats.ucsc.edu
Wed Feb 21 01:28:58 EST 2001


Hello All --

So I've got a number between 40 and 130 that I want to round up to the 
nearest 10.  That is:
   
   40 --> 40
   41 --> 50
   42 --> 50
   ...
   49 --> 50
   50 --> 50
   51 --> 60
   etc.

The way I'm doing it now is:

>>> import math
>>> depth = <<whatever>>
>>> tableDepth = int(math.ceil( depth/10.0 ) * 10)

(NAUI divers will recognize me translating from actual depth to a table 
depth entry)

This works just fine for my purposes, but its somewhat counterintuitive; 
I wonder if there is a more self-explanatory way...

Anyone have any ideas?

TIA,

Jacob



More information about the Python-list mailing list