import math
def test_round(a, b):
print('-------------------------------------')
print(f'{a}/{b}=', a/b)
print(f'{a}//{b}=', a//b)
print(f'round({a}/{b})=', round(a/b))
print(f'int({a}/{b})=', int(a/b))
print(f'ceil({a}/{b})=', math.ceil(a/b))
print(f'floor({a}/{b})=', math.floor(a/b))
test_round(3, 2)
test_round(-3, 2)
结果:
-------------------------------------
3/2= 1.5
3//2= 1
round(3/2)= 2
int(3/2)= 1
ceil(3/2)= 2
floor(3/2)= 1
-------------------------------------
-3/2= -1.5
-3//2= -2
round(-3/2)= -2
int(-3/2)= -1
ceil(-3/2)= -1
floor(-3/2)= -2
//
操作结果和floor
是一样的。
ceil:坐标轴上向上取整
floor:向下取整
int:向中(0)取整(直接去掉浮点位)
round则是四舍五入(不考虑符号)