python输入一个小数,提取整数部分

python输入一个小数,提取整数部分

a = 4.2 b =5.7

1.向下取整:int( )

int(a) = 4

int(b) = 5

2.向上取整:math.ceil( )
#需要先导入math库

math.ceil(a) = 5

math.ceil(b) = 6

3.四舍五入:round( )

round(a) = 4

round(b) = 6

学习笔记

扫描二维码关注公众号,回复: 13073608 查看本文章

猜你喜欢

转载自blog.csdn.net/m0_53052839/article/details/110356185