創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要介紹了python不保留小數(shù)的方法有哪些,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
1、int() 向下取整(內(nèi)置函數(shù))
n = 3.75 print(int(n)) >>> 3 n = 3.25 print(int(n)) >>> 3
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
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享python不保留小數(shù)的方法有哪些內(nèi)容對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!