Engineering numerical format PEP discussion

Keith keith.brafford at gmail.com
Mon Apr 26 21:12:16 EDT 2010


On Apr 26, 7:56 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> 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

Thanks, Mark, you're right.  It's clear that Decimal.to_eng_string()
doesn't solve the problem that I am trying to solve, which is: take
the Python "float" type, and print it in engineering format.

--Keith Brafford



More information about the Python-list mailing list