10

Is there a way to define the format style (number of decimals) for the Python module tabulate ?

For example:

I have the number 3.34643745.

I want to format the number of decimals to print out only two decimal places.

Output: 3.34

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Covich
  • 2,544
  • 4
  • 26
  • 37

1 Answers1

27

Yes you can do something like:

print tabulate([["pi",3.141593],["e",2.718282]], floatfmt=".2f")

Which will print:

--  ----
pi  3.14
e   2.71
--  ----

Here is a link to the documentation.

sebenalern
  • 2,515
  • 3
  • 26
  • 36