I have got output and I want to use only three values after decimal. How can i do that in Python?
+4
A:
Use the following:
"%.3f" % x
it converts your number to a string with three decimal places.
eumiro
2010-10-12 20:48:54
+4
A:
In Python 2.6 or newer you should use the str.format
method:
>>> x = 15.23432
>>> '{0:.3f}'.format(x)
'15.234'
Mark Byers
2010-10-12 20:50:25