python保留两位小数

>>> a = 1
>>> b = 3
>>> print(a/b)
>>> #方法一:
... print(round(a/b,2))
0.0
>>> #方法二:
... print(format(float(a)/float(b),'.2f'))
0.33
>>> #方法三:
... print ('%.2f' %(a/b))
0.00
>>>
posted @ 2019-01-14 17:23  JanWong  阅读(288)  评论(0编辑  收藏  举报