python取整数的方法

1、向下取整

a=1.3
b=1.7
a = int(a)
b = int(b)
print(a,b)

2、向上取整

import math
a = 1.3
b = 1.7
a = math.ceil(a)
b = math.ceil(b)
print(a,b)

3、四舍五入

a = 1.3
b = 1.7
a =round(a)
b =round(b)
print(a,b)

4、向下取整

import math
a = 1.3
b = 1.7
a =math.floor(a)
b =math.floor(b)
print(a,b)


上班求生存,下班求发展
原文地址:https://www.cnblogs.com/ljf520hj/p/12682371.html