新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何不保留小數(shù)
1、int() 向下取整(內(nèi)置函數(shù))

python學(xué)習(xí)網(wǎng),大量的免費(fèi)python視頻教程,歡迎在線學(xué)習(xí)!
n = 3.75 print(int(n)) >>> 3 n = 3.25 print(int(n)) >>> 3
相關(guān)推薦:《Python基礎(chǔ)教程》
2、round() 四舍五入(內(nèi)置函數(shù))
n = 3.75 print(round(n)) >>> 4 n = 3.25 print(round(n)) >>> 3
3、floor() 向下取整(math模塊函數(shù))
floor的英文釋義:地板。顧名思義也是向下取整
import math n = 3.75 print(math.floor(n)) >>> 3 n = 3.25 print(math.floor(n)) >>> 3
4、ceil()向上取整 (math模塊函數(shù))
ceil的英文釋義:天花板。
import math n = 3.75 print(math.ceil(n)) >>> 4 n = 3.25 print(math.ceil(n)) >>> 4
文章名稱:創(chuàng)新互聯(lián)Python教程:python如何不保留小數(shù)
瀏覽路徑:http://m.5511xx.com/article/djdiocs.html


咨詢
建站咨詢
