force non-exponential representation for Decimal?

Peter Otten __peter__ at web.de
Wed Dec 23 04:28:40 EST 2009


jholg at gmx.de wrote:

> I need to convert Python decimal.Decimal data to the XMLSchema xs:decimal
> datatype. This is reasonably straightforward, but there are some corner
> cases.
> 
> In particular, xs:decimal does not allow exponential notation like:
> 
>>>> print Decimal('0.00000000000000000023430000000837483727772')
> 2.3430000000837483727772E-19
>>>>
> 
> Is there a convenient way to force a decimal.Decimal representation to not
> use exponential representation?

> Any obvious alternatives I'm missing?

Decimal numbers seem to support new-style formatting:

>>> from decimal import Decimal
>>> d = Decimal('2.3430000000837483727772E-19')
>>> format(d, "f")
'0.00000000000000000023430000000837483727772'

Peter



More information about the Python-list mailing list