每天CookBook之Python-041

  • 数字的四舍五入
print(round(1.23, 1))
print(round(1.27, 1))
print(round(-1.27, 1))
print(round(1.25361, 3))

a = 1627731

print(round(a, -1))
print(round(a, -2))
print(round(a, -3))

x = 1.23456

print(format(x, '0.2f'))
print(format(x, '0.3f'))
print("value is {:0.3f}".format(x))

a = 2.1
b = 4.2
c = a + b

print(c)
print(round(c, 2))

Out:

1.2
1.3
-1.3
1.254
1627730
1627700
1628000
1.23
1.235
value is 1.235
6.300000000000001
6.3
posted @ 2016-07-18 23:51  4Thing  阅读(81)  评论(0编辑  收藏  举报