[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-03-02 Thread Mark Dickinson
Mark Dickinson added the comment: Closing here; the built-in formatting should be sufficient, as discussed. -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker _

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-26 Thread Mark Dickinson
Mark Dickinson added the comment: Sure, but that has nothing to do with string representations or formatting, so I don't see how it's relevant for this issue: the rounding happens when you call `normalize`. -- ___ Python tracker

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-26 Thread Szymon
Szymon added the comment: One more thing: It's worth mentioning that by default, you'll get only 28 significant digits of precision, so doing f"{Decimal('1234567890123456789012.12345678').normalize():f}" will produce '1234567890123456789012.123457' (two last digits got rounded). --

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-24 Thread Szymon
Szymon added the comment: Thanks for the replies. The use of format works great. Maybe it's worth mentioning in the documentation because using "%f" % Decimal("0.0001") leds to loosing precision (cast to float64 I guess) while using f"{"Decimal('0.0001'):f}" does the thing correctly.

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-24 Thread Steven D'Aprano
Steven D'Aprano added the comment: Python 3.5 to 3.9 are all in feature freeze and can accept no new features; new features can only be added to 3.10. But having said that, I agree with Mark that the correct solution here is to use format, not str. Szymon, unless you have a very argument aga

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-24 Thread Mark Dickinson
Mark Dickinson added the comment: This is by design: the choice of -6 is not arbitrary, but follows the standard that the Decimal class is based on. Quoting from http://speleotrove.com/decimal/daconvs.html#reftostr: > If the exponent is less than or equal to zero and the adjusted exponent is

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-24 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +facundobatista, mark.dickinson, rhettinger ___ Python tracker ___ ___ Python-bugs-lis

[issue43315] Decimal.__str__ has no way to force exact decimal representation

2021-02-24 Thread Szymon
New submission from Szymon : str(Decimal("0.0001")) always returns "1E-8" and there is no way to directly get the "0.0001" string back without writting custom method for converting DecimalTuple to string. This is caused by arbitrary choice of `and leftdigits > -6` condition in https: