[Python-Dev] Decimal conversion to string

Batista, Facundo FBatista at uniFON.com.ar
Wed Apr 14 17:58:11 EDT 2004


[Ka-Ping Yee]

#- 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')

To *me* is more natural the tuples. But that's only because that's what the
internal objects are.

An intermediate solution can be something like: 

>>> Decimal('12345')
Decimal(0, 12345, 0)

a tuple of three values: sign, coefficient, and exponent. The three of them
as integers.}

Anyway, if you want to change the repr() behaviour, you should push it hard
to the list. I'm -0 on it.

.	Facundo



More information about the Python-Dev mailing list