New submission from Mark Dickinson <dicki...@gmail.com>: In all versions of Python from 2.6 up, I get the following behaviour:
>>> format(123.456, '.4') '123.5' >>> format(1234.56, '.4') '1235.0' >>> format(12345.6, '.4') '1.235e+04' The first and third results are as I expect, but the second is somewhat misleading: it gives 5 significant digits when only 4 were requested, and moreover the last digit is incorrect. I propose that Python 2.7 and Python 3.1 be changed so that the output for the second line above is '1.235e+03'. Note that in both Python and C, '%.<precision>g' formatting switches to exponential notation at 1e<precision> precisely to avoid the problem of producing more significant digits than were requested; I'm proposing that the same solution be applied for '' formatting, except that since the empty format code is always required to produce at least one digit after the decimal point, the switch should happen at 1e<precision-1> instead of 1e<precision>. This change should not be backported to 2.6 or 3.0 since there's a small risk of breakage (particular in doctests). ---------- components: Interpreter Core messages: 86728 nosy: eric.smith, marketdickinson severity: normal stage: needs patch status: open title: format(1234.5, '.4') gives misleading result type: behavior versions: Python 2.7, Python 3.1 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5864> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com