码迷,mamicode.com
首页 > 编程语言 > 详细

python中取整的几种方法

时间:2018-05-27 10:38:57      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:float   oat   技术   src   eve   note   enc   分享   info   

#encoding:utf-8
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)
print "round(2) => ", round(2)

 

返回如下:

技术分享图片

 

python中取整的几种方法

标签:float   oat   技术   src   eve   note   enc   分享   info   

原文地址:https://www.cnblogs.com/VseYoung/p/python_numbers.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!