[Python-Dev] Decimal conversion to string (original) (raw)

Ka-Ping Yee python-dev at zesty.ca
Tue Apr 13 23:35:19 EDT 2004


Sorry if I missed this, but I didn't see a description in the PEP of how Decimal numbers would convert to other types. If d is a Decimal number, I assume int(d) is obvious and float(d) does the best it can with double precision, right?

How about str(d)? I would hope that it uses exponential notation only when necessary to preserve the number of significant digits.

Could we please have repr(d) use the string in the constructor rather than the tuple form? That would be much easier to read.

So, for example:

>>> Decimal('12345')
Decimal('12345')     # instead of Decimal((0, (1, 2, 3, 4, 5, 0))
>>> _ * 10
Decimal('1.2345e1')
>>> Decimal('12345', 2)
Decimal('1.2e3')
>>> Decimal(1.1)
Decimal('1.100000000000000088817841970012523233890533447265625')
>>> Decimal(1.1, default_context=1)
Decimal('1.10000000')

-- ?!ng



More information about the Python-Dev mailing list