Engineering numerical format PEP discussion

Mark Dickinson dickinsm at gmail.com
Mon Apr 26 19:56:39 EDT 2010


On Apr 26, 6:47 am, Keith <keith.braff... at gmail.com> wrote:
> From that document it appears that my decimal.Decimal(1234567) example
> shows that the module has a bug:
>
> Doc says:
> [0,123,3] ===>  "123E+3"
>
> But Python does:>>> import decimal
> >>> decimal.Decimal(123000).to_eng_string()
>
> '123000'

That's not a bug.  The triple [0,123,3] is Decimal('123e3'), which is
not the same thing as Decimal('123000').  The former has an exponent
of 3 (in the language of the specification), while the latter has an
exponent of 0.

>>> decimal.Decimal('123e3').to_eng_string()
'123E+3'

--
Mark



More information about the Python-list mailing list