新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:如何使用python中的取整floor函數(shù)?
如果一工程通過公式計算得出需要7.1輛汽車,直接取整成7輛肯定是完不成任務(wù)的,所以只有向上舍入成8才可以,即取整成7,再加1。取整加1,就是向上舍入成整數(shù)。相反,如果取整減1,那就是向下舍入成整數(shù),即向下取整。今天,我們就來認識一下python中向下取整函數(shù)floor函數(shù)。

1、floor()
得到最接近原數(shù)但是小于原數(shù)的部分
2、語法
import math math.floor(x)
注意:floor() 函數(shù)需要導(dǎo)入 math 模塊才能訪問,通過靜態(tài)對象調(diào)用該方法。
3、參數(shù)
x 數(shù)值表達式
4、返回值
返回數(shù)字的下舍整數(shù)。
5、使用
import math #這將導(dǎo)入math模塊
print("math.floor(-45.7):",math.floor(-45.7))
print("math.floor(45.7):",math.floor(45.7))
print("math.floor(-100.5):",math.floor(-100.5))
print("math.floor(100.5):",math.floor(100.5))輸出
math.floor(-45.7): -46 math.floor(45.7): 45 math.floor(-100.5): -101 math.floor(100.5): 100
以上就是向下取整函數(shù)的介紹,這個方法很方便,大家是可以輕松掌握的,要操作熟練哦~
分享標(biāo)題:創(chuàng)新互聯(lián)Python教程:如何使用python中的取整floor函數(shù)?
文章轉(zhuǎn)載:http://www.5511xx.com/article/dpiohhi.html


咨詢
建站咨詢
