3mty / prettytable

Automatically exported from
code.google.com/p/prettytable
Other
0 stars 0 forks source link

Alignment by decimal point #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
One very useful feature for displaying numerical data is aligning on the
decimal point. Implementing this is, of course, quite nontrivial, but
prettytable would be the ideal location for such code.

Original issue reported on code.google.com by robert.kern@gmail.com on 26 May 2009 at 4:19

GoogleCodeExporter commented 9 years ago
This should be Type-Enhancement, of course.

Original comment by robert.kern@gmail.com on 26 May 2009 at 4:20

GoogleCodeExporter commented 9 years ago
Sorry for the late response to this, Robert.  I haven't been checking the 
Issues tab
regularly because I assumed (incorrectly, it turns out) that I would get email
notifications about new issues.  Your enhancement request is a good one and I 
will
add it to my mental list of things to try out for PrettyTable 0.7.  Thanks!

Original comment by luke@maurits.id.au on 4 Jun 2009 at 2:03

GoogleCodeExporter commented 9 years ago
Hi,

I have just committed changes in response to Issue 10, which I think can be 
used to address your issue as well.  You can now use:

MyTable.float_format = "4.2"

to make sure that all floating point data in a table is printed using "%4.2f" 
formatting.  It is possible to use this to get an alignment by decimal.  If the 
largest floating point value in your table has, say, 5 digits in its 
non-decimal part, and you want to display floating point values with 2 digits 
after the decimal point, you could use a formatting string of 8.2 (the 8 comes 
from the maximum of 5 digits before the decimal point, plus 1 for the decimal 
point and then plus 2 for the digits after the point) and the result would look 
like this:

+--------------+
|    Values    |
+--------------+
|       2.35   |
|      61.88   |
|    1024.00   |
|   29109.60   |
|       3.14   |
+--------------+

Or you could use a formatting string of 08.2 to get leading 0s:

+--------------+
|    Values    |
+--------------+
|   00002.35   |
|   00061.88   |
|   01024.00   |
|   29109.60   |
|   00003.14   |
+--------------+

If this sort of approach meets the use case you had in mind (and you can 
remember that use case after me taking 3 years to act on this!), please let me 
know.  Or, if you had something else in mind, let me know that as well.

Original comment by luke@maurits.id.au on 24 Mar 2012 at 3:04

GoogleCodeExporter commented 9 years ago
Given lack of negative feedback about this change for over one month, I am now 
closing the issue as "Fixed".  If the current implementation of aligning on 
decimal points turns out to have shortcomings, people should feel free to 
submit a new Issue.

Original comment by luke@maurits.id.au on 1 May 2012 at 4:58