A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2004-April/044243.html below:

[Python-Dev] Decimal conversion to string

[Python-Dev] Decimal conversion to stringKa-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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4