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 wolma
Recipients eric.smith, ezio.melotti, mark.dickinson, martin.panter, rhettinger, scoder, serhiy.storchaka, skrah, tuomas.suutari, wolma
Date 2015-03-29.20:25:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427660715.26.0.514734214259.issue23602@psf.upfronthosting.co.za>
In-reply-to
Content
Initially, I also thought that this should be addressable with Fraction.__round__ or an optimized variation of it, but Tuomas is right that it gets complicated by the fact that you need to cope with the different format specifiers and not all of them fit the algorithm.
In particular, scientific notation poses a problem because it may require a lot more precision in the calculation than the one finally used for formatting. Consider:

>>> float(round(Fraction(4, 27000), 6))
0.000148

but
>>> format(4/27000, 'e')
'1.481481e-04'

Trying to deal with this in pure Python quickly slows your code (at least a few naive attempts of mine) unacceptably compared to Tuomas' patch.
History
Date User Action Args
2015-03-29 20:25:15wolmasetrecipients: + wolma, rhettinger, mark.dickinson, scoder, eric.smith, ezio.melotti, skrah, martin.panter, serhiy.storchaka, tuomas.suutari
2015-03-29 20:25:15wolmasetmessageid: <1427660715.26.0.514734214259.issue23602@psf.upfronthosting.co.za>
2015-03-29 20:25:15wolmalinkissue23602 messages
2015-03-29 20:25:14wolmacreate