Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round col entries to number of significant figures #10

Closed
GoogleCodeExporter opened this issue Aug 11, 2015 · 7 comments
Closed

Round col entries to number of significant figures #10

GoogleCodeExporter opened this issue Aug 11, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

Is this something that has being considered for future versions?  It'd be 
really nice if a format spec could be supplied for the formatting of all floats 
in a column or table e.g.

my_pretty_table.float_format_spec("4.2")

Original issue reported on code.google.com by willfurn...@gmail.com on 28 Feb 2012 at 11:22

@GoogleCodeExporter
Copy link
Author

Agreed.

Original comment by jadol...@gmail.com on 21 Mar 2012 at 5:30

@GoogleCodeExporter
Copy link
Author

Hi,

Thanks for the suggestion.  I agree that this would be a nice feature, and it 
doesn't seem too hard.  I will have a go at implementing it shortly.  For now 
I'll probably just go with one format spec for all columns rather than a 
per-column setting, just because I have a lot of feature requests which have 
piled up and I want to try to make fast progress on them.  But upgrading to a 
per-column setting later is a definite possibility.

Cheers,
Luke

Original comment by luke@maurits.id.au on 23 Mar 2012 at 3:55

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Hi,

I have just committed to the trunk of the svn repo with an implementation of 
this.  I would appreciate it very much if the people who have commented on this 
issue could give the new version a test and confirm whether or not it meets 
their needs.  Note, however, that if you have been using PrettyTable 0.5 until 
now, the API in the trunk version is substantially different.  Check out this 
Wiki page for instructions on how the new, cleaner API works: 
http://code.google.com/p/prettytable/wiki/Tutorial06

To set a floating point format for a PrettyTable object, just use:

MyTable.float_format = "4.2"

to print things using "%4.2f".  You can also do 04.2 to pad with leading 0s, 
etc.

Original comment by luke@maurits.id.au on 24 Mar 2012 at 2:53

@GoogleCodeExporter
Copy link
Author

Working well for me.  Thanks for adding the feature.  Per-column formats would 
be great.  

Original comment by willfurn...@gmail.com on 27 Mar 2012 at 12:47

@GoogleCodeExporter
Copy link
Author

Per-column formatting is now supported in the trunk version.  It works like 
this:

table.float_format["Foo"] = "4.2"
table.float_format["Bar"] = "2.4"
table.float_format["Baz"] = "123.321"

If you try to use the old style syntax and do:

table.float_format = "4.2"

then this will set a format of "4.2" to all columns, over-writing any 
per-column formatting you previously set up.

If you are interested in per-column formatting, please try to give this a test 
soon.  If I do not hear of any bugs with the new per-column formatting in a few 
days I will close this ticket, since I'm trying to get a clean Issue page to 
release 0.6, and people will have to open a new one to report bugs.

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

@GoogleCodeExporter
Copy link
Author

Forgot to mention - there is now similar support for integer formatting strings 
with the same interface as float formatting, e.g.

table.int_format["Foo"] = "05"

will print any integer data in the "Foo" column padded out to 5 characters with 
leading zeros.

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

@GoogleCodeExporter
Copy link
Author

Closing this issue since float formatting is now implemented and available on a 
per-column basis, and I've received no bug reports or negative feedback.  If 
anybody has float formatting requirements in the future which PrettyTable 
doesn't support, feel free to open a new ticket.

Original comment by luke@maurits.id.au on 4 May 2012 at 6:18

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant