[Python-Dev] Return type of round, floor, and ceil in 2.6

glyph at divmod.com glyph at divmod.com
Sat Jan 5 23:54:15 CET 2008


On 04:54 pm, guido at python.org wrote:
>On Jan 4, 2008 10:16 PM,  <glyph at divmod.com> wrote:

>>Having other rounding methods *available*, though, would be neat.  The
>>only application I've ever worked on where I cared about the 
>>difference,
>>the user had to select it (since accounting requirements differ by
>>jurisdiction and, apparently, by bank preference).  Having a standard
>>way to express this (especially if it worked across different numeric
>>types, but perhaps I digress) would be pleasant.  Implementing
>>stochastic rounding and banker's rounding oneself, while not exactly
>>hard, is a drag.
>
>The decimal module already supports rounding modes in its context. For
>other types, perhaps converting to decimal might be good enough?

Yes, that's the right thing to do.  I had missed it.  After all it is 
decimal rounding I want, and any financial applications I'm going to 
write these days are using decimals already for all the usual reasons.

At first I didn't realize why I'd missed this feature.  While the 
rounding *modes* are well documented, though, after 20 minutes of 
reading documentation I still haven't found a method or function that 
simply rounds a decimal to a given significant digit.  Is there one, 
should there be one, or is the user simply meant to use Context.quantize 
with appropriate arguments?


More information about the Python-Dev mailing list