Engineering numerical format PEP discussion

Stefan Krah stefan-usenet at
Mon Apr 26 11:04:35 CEST 2010

Chris Rebert <clp2 at> wrote:
> >>>> c = decimal.Context(prec=5)
> >>>> decimal.Decimal(1234567).to_eng_string(c)
> > '1234567'
> >
> > That is not an engineering notation string.
> Apparently either you and the General Decimal Arithmetic spec differ
> on what constitutes engineering notation, there's a bug in the Python
> decimal library, or you're hitting some obscure part of the spec's
> definition. I don't have the expertise to know which is the case.
> The spec:
> (to-engineering-string is on page 20 if you're interested)

The module is correct. Printing without exponent follows the same rules
as to-scientific-string:

"If the exponent is less than or equal to zero and the adjusted exponent
 is greater than or equal to -6, the number will be converted to a
 character form without using exponential notation."

Stefan Krah

More information about the Python-list mailing list