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