A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-January/075909.html below:

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

[Python-Dev] Return type of round, floor, and ceil in 2.6Mark Dickinson dickinsm at gmail.com
Sun Jan 6 00:34:05 CET 2008
On Jan 5, 2008 5:54 PM, <glyph at divmod.com> wrote:

> 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?
>

quantize is about as close as it gets.  Note that it's a Decimal method as
well as a Context method, so you can invoke it directly on a given decimal:

>>> Decimal("2.34567").quantize(Decimal("0.01"))
Decimal("2.35")

I've also occasionally felt a need for a simple rounding function that isn't
affected by context.  Would others be interested in such a function being
added to Decimal?  I guess there are two possibly useful operations:  (1)
round to a particular decimal place ( e.g. nearest ten, nearest hundredth,
..) and (2) to round to a particular number of significant digits;  in both
cases, the user should be able to specify the desired rounding mode.  And
for each operation, it might also be useful to specify whether the result
should be padded with zeros to the desired length or not.  (i.e. when
rounding 3.399 to 3 significant places, should it produce 3.4 or 3.40?)

Any thoughts?

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20080105/773cbef5/attachment.htm 
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4