This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tuomas.suutari
Recipients eric.smith, ezio.melotti, mark.dickinson, martin.panter, rhettinger, scoder, serhiy.storchaka, skrah, tuomas.suutari, wolma
Date 2015-03-29.17:07:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAPXCX8CPpQtnNQ34-dEx5g6YVzvgXGAif063MR5K5-3w43eB=g@mail.gmail.com>
In-reply-to <[email protected]>
Content
On 29 March 2015 at 19:54, Serhiy Storchaka wrote:
> I think that Decimal is not needed for Fraction.__format__ (and I'm not sure that issue23602v4.patch is correct).

Of course it's not needed. I'm using it to avoid re-implementing all
the various formatting variations that can be controlled with the
fill/align/sign/width/,/precision/type parameters
(https://docs.python.org/3/library/string.html#formatspec). IMHO those
should be supported as they are with floats and Decimals.

> The correct way to format Fraction as fixed-precision decimal is to use Fraction.__round__() or similar algorithm. The implementation can look like:
>
>     f = self.__round__(prec)
>     i = int(f)
>     return '%d.%0*d' % (i, prec, abs(f - i) * 10**prec)

Why this would be more correct than delegating the rounding (and
formatting) to Decimal.__format__? (Then we just have to make sure
that we have enough precision in the decimal context we're operating
in. That's what I got wrong in the previous round.)
History
Date User Action Args
2015-03-29 17:07:02tuomas.suutarisetrecipients: + tuomas.suutari, rhettinger, mark.dickinson, scoder, eric.smith, ezio.melotti, skrah, martin.panter, serhiy.storchaka, wolma
2015-03-29 17:07:02tuomas.suutarilinkissue23602 messages
2015-03-29 17:07:01tuomas.suutaricreate