python 向上取整ceil 向下取整floor 四舍五入round
发布时间:2020-12-20 10:43:57 所属栏目:Python 来源:网络整理
导读: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) = "
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 "nnNOTE: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) 运行结果: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |