Decimal printing without the exponent

Raymond Hettinger vze4rx4y at verizon.net
Mon Nov 29 01:49:36 EST 2004


"Bryan" <belred1 at yahoo.com> wrote in message
news:%0oqd.478158$D%.433430 at attbi_s51...
> is there a way to make the Decimal class not print the exponent version of the
> decimal?
>
>
>  >>> str(Decimal('1010'))
> '1010'
>  >>> str(Decimal((0, (1, 0, 1), 1)))
> '1.01E+3'
>  >>>
>
> how do you make the 2nd example print 1010?


The quantize method will convert to any desired exponent (zero in your example):

>>> d = (Decimal((0, (1, 0, 1), 1)))
>>> d
Decimal("1.01E+3")
>>> d.quantize(Decimal(1))
Decimal("1010")



Raymond Hettinger





More information about the Python-list mailing list