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)



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM