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

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

时间:2019-09-14 00:15:28      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:--   python   com   col   返回结果   enc   utf-8   round   四舍五入   

 1 #encoding:utf-8
 2 import math
 3 
 4 #向上取整
 5 print "math.ceil---"
 6 print "math.ceil(2.3) => ", math.ceil(2.3)
 7 print "math.ceil(2.6) => ", math.ceil(2.6)
 8 
 9 #向下取整
10 print "\nmath.floor---"
11 print "math.floor(2.3) => ", math.floor(2.3)
12 print "math.floor(2.6) => ", math.floor(2.6)
13 
14 #四舍五入
15 print "\nround---"
16 print "round(2.3) => ", round(2.3)
17 print "round(2.6) => ", round(2.6)
18 
19 #这三个的返回结果都是浮点型
20 print "\n\nNOTE:every result is type of float"
21 print "math.ceil(2) => ", math.ceil(2)
22 print "math.floor(2) => ", math.floor(2)
23 print "round(2) => ", round(2)

运行结果:

技术图片

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

标签:--   python   com   col   返回结果   enc   utf-8   round   四舍五入   

原文地址:https://www.cnblogs.com/lewuyou/p/11517818.html

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