2024-04-25 18:23:54 发布
网友
我正在使用Python3.4.3。math.floor函数为正数和负数给出了不同的答案。例如:
math.floor
>>> math.floor (19.8) 19 >>> math.floor (-19.8) -20
为什么我的答案会有这么大的差别?
根据documentation:
Return the floor of x as a float, the largest integer value less than or equal to x.
math.floor()总是返回最接近的下整数值。记住这一点,-20<-19.8<-19So-20按预期返回。
math.floor()
-20<-19.8<-19
另一方面,对于正整数,比如5.5,5<5.5<6,所以math.floor()在这里返回5。
5<5.5<6
原因是地板的功能减弱了。所以19.8发子弹减至19发,而-19.8发子弹减至-20发,因为-20小于-19.8发。
floor是greatest integer函数,表示小于给定值的最大整数。
floor
greatest integer
-20 < -19.5 < -19 --> -20 is the greatest integer less than -19.5 19 < 19.5 < 20 --> 19 is the greatest integer less than 19.5
根据documentation:
math.floor()
总是返回最接近的下整数值。记住这一点,-20<-19.8<-19
So-20按预期返回。另一方面,对于正整数,比如5.5,
5<5.5<6
,所以math.floor()
在这里返回5。原因是地板的功能减弱了。所以19.8发子弹减至19发,而-19.8发子弹减至-20发,因为-20小于-19.8发。
floor
是greatest integer
函数,表示小于给定值的最大整数。相关问题 更多 >
编程相关推荐