How can I put only value after decimal
I have got output and I want to use only three values开发者_开发问答 after decimal. How can i do that in Python?
Use the following:
"%.3f" % x
it converts your number to a string with three decimal places.
In Python 2.6 or newer you should use the str.format
method:
>>> x = 15.23432
>>> '{0:.3f}'.format(x)
'15.234'
round(number, 3)
http://docs.python.org/tutorial/floatingpoint.html
精彩评论