Python函数之 ceil, floor,round
Ceiling是向上取整
floor是向下取整
Round是四舍五入的
ceil
描述
ceil() 函数返回数字的上入整数
ceil():将小数部分一律向整数部分进位。
#!/usr/bin/python
import math # This will import math moduleprint "math.ceil(-45.17) : ", math.ceil(-45.17)
print "math.ceil(100.12) : ", math.ceil(100.12)
print "math.ceil(100.72) : ", math.ceil(100.72)
print "math.ceil(119L) : ", math.ceil(119L)
print "math.ceil(math.pi) : ", math.ceil(math.pi)
输出结果为:
math.ceil(-45.17) : -45.0
math.ceil(100.12) : 101.0
math.ceil(100.72) : 101.0
math.ceil(119L) : 119.0
math.ceil(math.pi) : 4.0
#向上取整
print "math.ceil---"
print "math.ceil(2.3) => ", math.ceil(2.3)
print "math.ceil(2.6) => ", math.ceil(2.6)
floor
floor():一律舍去,仅保留整数
math.floor(12.2)// 返回12
math.floor(12.7)//返回12
math.floor(12.0)//返回12
#向下取整
print "\nmath.floor---"
print "math.floor(2.3) => ", math.floor(2.3)
print "math.floor(2.6) => ", math.floor(2.6)
round
round():进行四舍五入
math.round(12.2)// 返回12
math.round(12.7)//返回13
math.round(12.0)//返回12
#encoding:utf-8
import math#这三个的返回结果都是浮点型
print "\n\nNOTE:every result is type of float"
print "math.ceil(2) => ", math.ceil(2)
print "math.floor(2) => ", math.floor(2)
print "round(2) => ", round(2)
Python函数之 ceil, floor,round相关推荐
- C++ 多种取整函数的使用和区别: ceil() floor() round() trunc() rint() nearbyint()
取整函数: ceil() 右向取整:数轴上右边最靠近的整数,向大的方向取值:ceil "天花板" floor() 左向取整:数轴上左边最靠近的整数,向小的方向取值:fl ...
- php 取整 ceil,PHP取整函数:ceil,floor,round,intval有什么不同
PHP取整函数:ceil,floor,round,intval有什么不同 发布时间:2021-02-13 09:03:11 来源:亿速云 阅读:76 作者:Leah PHP取整函数:ceil,floo ...
- php坐标轴取整,PHP取整函数:ceil,floor,round,intval的区别详细解析
我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. ceil -- 进一法取整说明float ceil ( float value ) 返回不小于 value 的下 ...
- php 取整函数 ceil floor round intval 随笔
ceil() 进一法取整 echo ceil(4.5);// 5 //float类型 floor() 去一法取整 echo floor(4.5);// 4 //float类型 round(float ...
- php 上取整函数是,PHP取整函数:ceil,floor,round,intval的区别详细解析
搜索热词 PHP取整函数,主要是:ceil,floor,round,intval. 说明float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小 ...
- php floor intval,php取整函数floor(),round(),intval(),ceil()
ceil -- 进一法取整 说明 float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 flo ...
- C++ floor、ceil、round函数的区别
函数解释 floor函数,向下取整.即向负无穷方向取离传入参数最近的整数 ceil函数,向上取整.即向正无穷方向取离传入参数最近的整数 round函数,四舍五入. 头文件 C语言:math.h C++ ...
- Oracle的取整和四舍五入函数——floor,round,ceil,trunc使用说明
oracle的取整和四舍五入函数--floor round ceil trunc使用说明 看了electrictoolbox上对PHP,MYSQL,Javascript几种语言关于取整数的专题, ...
- 向下取整floor()、向上取整ceil()、截取函数trunc()、四舍五入round()
简介: floor函数 ceil函数 round函数 trunc()函数 简介: Floor() 不大于自变量的最大整数 Ceil() 不小于自变量的最大整数 Round() 四舍五入到最邻近的整 ...
最新文章
- Docker系列07—Dockerfile 详解
- seaborn.FacetGrid
- boost::fusion::count用法的测试程序
- MySql like 查询 变向写法(不用like 完成like查询)
- shell脚本详解(八)——一键部署自动化装机(PXE无人值守)
- python 更新数据库历史_python 实现数据库中数据添加、查询与更新的示例代码
- 要来吗,不错的WPF技术交流群!(大批干货今日自取)
- golang 反射_Golang 会淘汰 Python 吗?
- 你知道,什么时候用Vue计算属性吗?
- 带你看论文丨全局信息对于图网络文档解析的影响
- 关于linux目录~ / .
- 屏幕取词翻译软件:Lingoes 灵格斯词霸
- 普通人下场全球贸易,新一轮结构性机会浮出水面
- [排序算法] 13. 常见排序算法总结及运用高精度计时模板测试性能(复杂度分析、高精度计时、总结)
- linux处理僵尸进程
- HTC Vive与Oculus Rift全面对比
- 无线串口模块通信技术参数快速选型指南
- Apple Mac购买Pro App 套装 优惠方案
- 云南省初中计算机说课稿,云南省实验教材《信息技术》说课稿范文(9页)-原创力文档...
- Exynos4412开发板
热门文章
- android系统设置在哪里,android-如何在系统settings里添加设置选项
- [蓝桥杯][算法提高VIP]Sharing Chocolate(状压dp记忆化搜索)
- oracle查询pga大小GB,Oracle如何调整SGA和PGA的大小
- mysql 锁怎么使用_Mysql锁一般使用
- 分布式的客户端-服务器结构_MMORPG游戏服务器技术选型参考
- 计算机组成原理--主存储器
- 『数据库』 E-R图(实体联系图)你都不会,你设计什么数据库?
- linux系统如何使用fork函数创建子进程
- Tensorflow Serving 介绍
- VxWorks关于任务创建的几个函数的概述