Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's tabulate number of decimal [closed]

Tags:

python

format

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

like image 244
Covich Avatar asked May 06 '16 19:05

Covich


1 Answers

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.

like image 173
sebenalern Avatar answered Sep 18 '22 11:09

sebenalern