7

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,438
  • 68
  • 55
  • 126
Covich
  • 2,285
  • 3
  • 21
  • 34

1 Answers1

19

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,425
  • 3
  • 23
  • 34