您当前的位置: 首页 >  Python

Python浮点数转整数int、round、ceil、floor

彭世瑜 发布时间:2019-10-14 19:29:51 ,浏览量:3

# int 向0取整
int(-0.5)  # 0
int(0.5)  # 0


# round四舍五入,向偶取整
round(0.5)  # 0
round(0.9)  # 1
round(1.5)  # 2


import math

# math.floor 向下取整
math.floor(0.9)  # 0
math.floor(-0.9)  # -1


# math.ceil 向上取整
math.ceil(0.5)  # 1
math.ceil(-0.5)  # 0

参考 Python取整——向上取整、向下取整、四舍五入取整、向0取整

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.5732s