python中的取整
python,取整
2025-04-07 09:01:24 时间
大家好,又见面了,我是你们的朋友全栈君。
处理数据时,经常会遇到取整的问题,现总结如下
1,向下取整 int()
1 >>>a = 3.1
2 >>>b = 3.7
3 >>>int(a)
3
4 >>>int(b)
3
5 >>>int(-a)
-3
6 >>>int(-b)
-3
2,向上取整 math.ceil()
1 >>>from math import ceil
2 >>>a = 3.1
3 >>>b = 3.7
4 >>>ceil(a)
5 4
6 >>>ceil(b)
7 4
8 >>>ceil(-a)
9 -3
10 >>>ceil(-b)
11 -3
3,四舍五入 round()
1 >>>a = 3.123
2 >>>b = 3.256
3 >>>round(a)
4 3.0
5 >>>round(a, 2)
6 3.12
7 >>>round(b, 2)
8 3.26
9 >>>round(b, 1)
10 3.3
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155889.html原文链接:https://javaforall.cn
相关文章
- pyinstaller打包python-docx报错 No such file or directory (default-header.xml)
- Python项目51-课程页面
- 自动化神器!Python 批量读取身份证信息写入 Excel
- Python浪漫表白源码合集(爱心、玫瑰花、照片墙、星空下的告白)「建议收藏」
- python re.compile() 详解——Python正则表达式「建议收藏」
- 快过年了,用Python写副春联&福字送给你~
- 支持向量机(SVM)的分析及python实现「建议收藏」
- 使用Python检测符号及乱码字符
- Python-drf前戏38.3-前端Vue03
- python 基尼系数_Python计算
- 2022春节贺岁档电影开分,水门桥不理想,四海崩了!用Python一探究竟
- XGBoost:在Python中使用XGBoost
- Python 的数据结构
- Python日志管理
- python有趣的实验1(里面很好玩哦)
- Python基本数据类型-字符型
- CPD 算法实现点云配准(python版本)[通俗易懂]
- Python模拟一个用户登录系统
- 【敬初学者】Python基础学完了,该怎么知道自己学的怎么样呢?十个经典实战小项目附源码
- python实现卷积操作