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

python 向上取整ceil 向下取整floor 四舍五入round

时间:2014-05-08 12:11:13      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   color   

bubuko.com,布布扣
#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)
bubuko.com,布布扣

运行结果:

bubuko.com,布布扣

 

 

python 向上取整ceil 向下取整floor 四舍五入round,布布扣,bubuko.com

python 向上取整ceil 向下取整floor 四舍五入round

标签:style   blog   class   code   java   color   

原文地址:http://www.cnblogs.com/lipijin/p/3714312.html

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