开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜