[New-bugs-announce] [issue43315] Decimal.__str__ has no way to force exact decimal representation
report at bugs.python.org
Wed Feb 24 05:59:48 EST 2021
New submission from Szymon <szymon1313 at gmail.com>:
str(Decimal("0.00000001")) always returns "1E-8" and there is no way to directly get the "0.00000001" string back without writting custom method for converting DecimalTuple to string. This is caused by arbitrary choice of `and leftdigits > -6` condition in https://github.com/python/cpython/blob/master/Lib/_pydecimal.py#L1052 .
The hardcoded value of -6 should be parametrizable. This can be done by adding it as argument to the __str__ method or maybe by adding it to the decimal context.
title: Decimal.__str__ has no way to force exact decimal representation
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce