python中的向上取整向下取整以及四舍五入的方法
import math
#向上取整
print "math.ceil---"
print "math.ceil(2.3) => ", math.ceil(2.3)
print "math.ceil(2.6) => ", math.ceil(2.6)
#向下取整
print "\nmath.floor---"
print "math.floor(2.3) => ", math.floor(2.3)
print "math.floor(2.6) => ", math.floor(2.6)
#四舍五入
print "\nround---"
print "round(2.3) => ", round(2.3)
print "round(2.6) => ", round(2.6)
#这三个的返回结果都是浮点型
print "\n\nNOTE:every result is type of float"
print "math.ceil(2) => ", math.ceil(2)
print "math.floor(2) => ", math.floor(2)
---------------------
作者:稚枭天卓
来源:CSDN
原文:https://blog.csdn.net/u013630349/article/details/47298977
版权声明:本文为博主原创文章,转载请附上博文链接!
python中的向上取整向下取整以及四舍五入的方法的更多相关文章
- C#采用的是“四舍六入五成双”、上取整、下取整
c# 四舍五入.上取整.下取整 Posted on 2010-07-28 12:54 碧水寒潭 阅读(57826) 评论(4) 编辑 收藏 在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采 ...
- c# 四舍五入、上取整、下取整
在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采用的是“四舍六入五成双”的方法,如下面的例子,就是用“四舍六入五成双”得到的结果: double d1 = Math.Round(1.25, ...
- c#中取整,向上取,向下取
Math.Ceiling()向上取整, Math.Floor()向下取整 示例: d = 4.56789 Math.Ceiling(Convert.ToDecimal(d)).ToString();M ...
- Python向上取整,向下取整以及四舍五入函数
import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...
- python向上取整 向下取整
向上取整 ceil() 函数返回数字的向上取整整数,就是返回大于等于变量的最近的整数. ceil()是不能直接访问的,需要导入 math 模块. import math math.ceil( x ) ...
- python取整函数 向上取整 向下取整 四舍五入
向上取整 >>> import math >>> math.ceil(3.5) 4 >>> math.ceil(3.4) 4 >>&g ...
- SQLSERVER 数值 四舍五入取整 向上取整 向下取整
[四舍五入取整截取] select round(54.56,0) [向下取整截取] SELECT floor(54.56) [向上取整截取] SELECT ceiling(13.15)
- C#以及Oracle中的上取整、下取整方法
1.C#中: 上取整——Math.Ceiling(Double),即返回大于或等于指定双精度浮点数的最大整数(也可称为取天板值): eg: Math.Ceiling(1.01)=2; Ma ...
- #python计算结果百位500向下取整,(0-499取000,500-999取500)
!/usr/bin/env python coding:utf-8 计算结果百位500向下取整,(0-499取000,500-999取500) import math calc_Amount = fl ...
随机推荐
- CF1139C Edgy Trees
题目地址:CF1139C Edgy Trees 红黑树 \(ans\) 应该等于总数(\(n^k\))减去不含黑色边的序列数量 不含黑色边就意味着一个序列只能在一个红色联通块中 一个红色联通块中的序列 ...
- RabbitMQ环境搭建
消息 RabbitMQ 1.安装erlang环境 2.安装rabbitmq 3.参考资料 AMQP协议,可以跨语言通信 Advance Message Queuing Protocol Rabbit ...
- 【原创】大数据基础之ElasticSearch(4)es数据导入过程
1 准备analyzer 内置analyzer 参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis- ...
- springboot ****使用经验*******
目录 1. 返回时间格式化问题 2. springboot 中获取属性 3. SpringBoot中启动是忽略某项检测 4. 启动不开启安全校验 一返回时间格式化问题 在Spring Boot项目中 ...
- vue-i18n国际化在data中切换不起作用
vue-i18n是一个针对于vue的国际化插件,使用非常简单,具体使用方式看我细细道来. 实现方式 1. 下载包 npm install vue-i18n 2. 配置 在main.js文件中加入如下配 ...
- IP地址分类(A类 B类 C类 D类 E类)
IP地址分类(A类 B类 C类 D类 E类) IP地址由四段组成,每个字段是一个字节,8位,最大值是255,, IP地址由两部分组成,即网络地址和主机地址.网络地址表示其属于互联网的哪一个网络,主机地 ...
- LQFP(未整理完成)
注意:文中所提供的链接有可能会失效.不定期维护,如有异常,期待指正,谢谢! LQFP48 7 x 7 mm 图片来源:https://www.st.com/resource/en/datasheet/ ...
- SpringBoot webmvc项目导出war包并在外部tomcat运行产生的诸多问题以及解决方案
背景: 有需求要将原来的Spring(3.2.6) + Springmvc + Hibernate项目重构为Springboot(1.5.2)项目 描述: 记录重构过程,以及期间遇到的种种问题和对应的 ...
- jquery刷新页面代码
window.location.reload()刷新当前页面.parent.location.reload()刷新父亲对象(用于框架)opener.location.reload()刷新父窗口对象(用 ...
- 解决使用maven的java web项目导入后出现的有关问题 -cannot be read or is not a valid ZIP file
解决使用maven的java web项目导入后出现的有关问题 -cannot be read or is not a valid ZIP file 错误问题:虽然查找repository目录下是有 ...