Snip77 Snip77 - 28 days ago 5
Python Question

Calculate up to two decimal places in Python

I want to Calculate up to two decimal places in my Calculations but I can't

For example:

a = 93
b = 1
c = float(93/1)
print c


I want to
print
like this :

93.00


But it print like this :

93.0


Is there any function to do this or is there any way to do this?

Answer Source

use an explicit format to that float

print("%.2f" % round(c,2))

test it on a jupyter

https://try.jupyter.org/


enter image description here