math module for Decimals
Mark Dickinson
dickinsm at gmail.com
Sun Dec 28 09:38:32 EST 2008
On Dec 28, 7:28 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> 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 bugs.python.org 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
Decimal('3.141592653589793115997963469')
Mark
More information about the Python-list
mailing list