
大家好,又见面了,我是你们的朋友全栈君。
脑海里想象出一根坐标轴,左右分别指向负无穷和正无穷,如果需要所取的变成:
math.ceil()取正方向上最近的一个整数。
print(math.ceil(9.1))10math.floor()取负方向上最近的一个整数
print(math.floor(-9.1))-10附:向上取整,注:numpy 中对应使用 np.ceil 和 np.floor ,而且其返回浮点数而不是整数!!(在 python3 中 math.ceil 和 math.floor 返回整数) 参考:点击
int()向0方向取最近的一个整数,或者直接理解为砍掉小数部分。
print(int(9.8))
print(int(-9.8))9
-9round()向自己取整,小于0.5取自己的整数部分。
print(round(9.1))
print(round(-9.8))9
-10发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126067.html原文链接:https://javaforall.cn