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 ...
随机推荐
- 【转】QPainter中坐标系变换问题
转自:http://blog.sina.com.cn/s/blog_67cf08270100ww0p.html 一.坐标系简介. Qt中每一个窗口都有一个坐标系,默认的,窗口左上角为坐标原点,然后水平 ...
- VOC2012数据集注解
VOC2012官网介绍:http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html 分割部分:参考博客:https://blog.csdn.ne ...
- 【转】使用keepalived设置虚拟IP示例
准备 准备两台机器,IP地址信息如下: host1: 192.168.56.103 host2: 192.168.56.104 为了测试需要,分别在两台机器上安装apache并启动httpd服务,使下 ...
- .\OBJ\test1.axf: Error: L6230W: Ignoring --entry command. Cannot find argumen 'Reset_Handler'
原因是缺少了启动文件,startup_xxx.s,只需要把该文件添加到项目下即可,该文件如果找不到则重新建立工程,每个新的工程建立后系统都会询问是否添加启动文件,选择添加启动文件即可. 注意选择对应容 ...
- C#VS2017添加ReportViewer控件
安装完vs2017之后我们进行添加Report Viewer控件: 1. 点击Tools -> Extensions and Updates... 2. 在新窗口搜索栏中输入rdlc后搜索,结果 ...
- vue ssr github 项目及其 文章
https://github.com/Liao123/vue-js-webpack-ssr 这个项目可以完美运行 npm run start 是运行
- Monkey自动化脚本(一)
1.Monkey简介 Monkey-猴子,通过Monkey程序模拟用户触摸屏幕.滑动Trackball. 按键等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常,主要用于Android ...
- 《剑指offer》复杂链表的复制
本题来自<剑指offer> 反转链表 题目: 思路: C++ Code: Python Code: 总结:
- css实现右尖括号样式
.arrow{ width: 6px; height: 6px; border-top: 1px solid #999; border-right: 1px solid #999; transform ...
- 烽火R2600交换机配置脚本
烽火交换机端口映射配置 ip nat inside source static udp iP 端口号 公网iP 端口号 ip nat inside source interface Vlan-intf ...