math module for Decimals

Mark Dickinson dickinsm at
Sun Dec 28 15:38:32 CET 2008

On Dec 28, 7:28 am, Steven D'Aprano <st... at REMOVE-THIS-> wrote:
> Ah crap, I forgot that from_float() has been left out of the decimal API.
> That's very annoying.

Agreed.  It's maybe even annoying enough that a feature request
at might be honoured.  (Hint, hint!)

It's fairly easy to emulate in Python 2.6 and above, using the
as_integer_ratio float method:

>>> from decimal import Decimal
>>> from math import pi
>>> n, d = pi.as_integer_ratio()
>>> Decimal(n)/d


More information about the Python-list mailing list