开发者

How can I put only value after decimal

开发者 https://www.devze.com 2023-01-20 11:12 出处:网络
I have got output and I want to use only three values开发者_开发问答 after decimal. How can i do that in Python?Use the following:

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

精彩评论

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