Keith Brafford <keith.braff...@gmail.com> added the comment: Ok, let's zero in on how this should work. I'll start the concrete proposal discussion in terms of how it would have worked with the old-style specifiers (since I am more familiar with that method) and we can bring it up to Py3K standards as a group.
I was thinking something along these lines: %[<space> | 0 ][.precision]m where the optional space or zero means that you want the whole number part of the output to be padded to three digits, either with spaces or prepended zeroes. No space or zero means no prepending of anything. The .precision would be the number of digits after the decimal point you want to see. If you don't specify this, then the default would be something that people agreed made the most sense, say 4 for now. f = math.pi * 1e-5 print f 3.1415926535897935e-005 print "%m" % f 31.4159e-06 print "% m" % f 31.4159e-06 print "%0m" % f 031.4159e-06 print "% m.6" % f 31.415927e-06 Mark brought up this point: e.g. format(12345.678, '.5m'): Should the '5' indicate 5 digits after the point (giving '12.34568e+3' in this case), or 5 significant digits in total (giving '12.345e+3'). I tend to think that it's more important that the precision number tell you the number of digits after the decimal point. This is because the underlying float still has all of the precision, and the format specifier is used simply to make the printout look correct. Being able to specify that you want three slots before the point, then a constant number after the point lets you get perfectly aligned columns in a tabular printout without a lot of fuss. I wrote a class that I've been using to test these formats out with (attached). I use it like this: >>> from efloat impot EFloat as E it has a class "precision" value that you can set: >>> E.precision = 5 >>> E(math.pi) 3.14159e+0 >>> E(math.pi / 1e-9) 3.14159e+9 >>> E(math.pi / 1e-2) 314.15927e+0 >>> E(math.pi / 1e-5) 314.15927e+3 It has a slight bug, though. It doesn't give me two digits of exponent, which would be required in the engineering format specifier, IMHO, so that programmers can easily get constant tabular column widths. ---------- nosy: +Keith.Brafford Added file: http://bugs.python.org/file17111/efloat.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8060> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com