Message 239495 - Python tracker (original) (raw)

Thanks for the comments again!

I fixed the "format(F(4, 27), '.1f') -> 0.2" issue Serhiy Storchaka reported. Fix for that was as simple as adding one to the precision the decimals are calculated in, but while adding test cases for that I realized two new things:

(a) I don't want "f" specifier to mean "infinite" precision, but instead some predefined value. I chose 6. (b) How about rounding? I don't want the current decimal context to affect that, since it's not logical that formatting of Fractions depends on the decimal context.

The rounding thing made things harder, since there was no way to pass decimal context for Decimal.format without changing the local context -- at least with the C implementation; the Python implementation (_pydecimal) provided nicer API with optional context keyword argument. So I decided to unify the C and Py API's of Decimal.format and add the keyword argument support to the C API too. This is done in this v4 of the patch.

There's no docs for the added Decimal.format kwargs, since I want some comments on that change first.