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

python中的math.ceil(x)和math.floor(x)

时间:2016-12-01 14:50:22      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:部分   link   jin   int   view   title   com   bsp   nbsp   

一 math.ceil(x)

import math

1、当x为正数时,只要x的小数部分>0就+1

x=5.01

print(math.ceil(x)) #6

x=5.9

print(maht.ceil(x)) #6

 

2、当x为负数时,舍去小数部分

x=-5.9

print(math.ceil(x)) #-5

x=-5.01

print(math.ceil(x)) #-5

 

二、math.floor(x)

1、当x为正数时,舍去小数部分

x=5.9

print(math.floor(x)) #5

x=5.01

print(math.floor(x)) #5

2、当x为负数时,只要小数部分>0,就+-1

x=-5.9

print(math.floor(x)) #-5-1=-6

x=-5.01

print(math.floor(x)) #-5-1=-6

 

http://www.cnblogs.com/liujinxin/p/6121495.html 

python中的math.ceil(x)和math.floor(x)

标签:部分   link   jin   int   view   title   com   bsp   nbsp   

原文地址:http://www.cnblogs.com/liujinxin/p/6121495.html

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