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)


posted @ 2020-04-11 21:30  呆呆蒙蒙  阅读(1184)  评论(0)    收藏  举报