使用int()实现四舍五入
程序员文章站
2022-04-09 09:00:19
...
代码如下:
class Debug:
def __init__(self):
self.x0 = 0.4
self.x1 = 0.5
self.x2 = 0.6
def mainProgram(self):
self.x0 = int(self.x0 + 0.5)
self.x1 = int(self.x1 + 0.5)
self.x2 = int(self.x2 + 0.5)
print(self.x0) # 0
print(self.x1) # 1
print(self.x2) # 1
main = Debug()
main.mainProgram()
当变量值为0.4
的时候结果为0
,变量值为0.5
和0.6
的时候结果为1
。
上一篇: PHP伪静态
推荐阅读
-
Java Web使用Html5 FormData实现多文件上传功能
-
MyBatis之自查询使用递归实现 N级联动效果(两种实现方式)
-
UnityShader使用图像叠加实现运动模糊
-
UnityShader使用速度映射图实现运动模糊
-
android使用Messenger绑定Service的多种实现方法
-
使用Python实现将list中的每一项的首字母大写
-
使用Flask-Cache缓存实现给Flask提速的方法详解
-
tp5框架使用composer实现日志记录功能示例
-
Android使用WebSocket实现多人游戏
-
Android 使用 DowanloadManager 实现下载并获取下载进度实例代码