Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1694549
  • 博文数量: 362
  • 博客积分: 10587
  • 博客等级: 上将
  • 技术积分: 4098
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-10 18:15
文章分类

全部博文(362)

文章存档

2014年(1)

2013年(58)

2011年(115)

2010年(112)

2009年(76)

分类: Python/Ruby

2009-10-29 16:14:06

用4个正数和4个负数作为3个函数的参数,将返回结果做个比较

 

>>> for eachnum in (.2,.7,1.2,1.7,-1.2,-1.7):
 print "int(%.1f)\t%+.1f" % (eachnum,float(int(eachnum)))
 print "floor(%.1f)\t%+.1f" % (eachnum,math.floor(eachnum))
 print "round(%.1f)\t%+.1f" % (eachnum,round(eachnum))
 print '-' * 20


 
int(0.2) +0.0
floor(0.2) +0.0
round(0.2) +0.0
--------------------
int(0.7) +0.0
floor(0.7) +0.0
round(0.7) +1.0
--------------------
int(1.2) +1.0
floor(1.2) +1.0
round(1.2) +1.0
--------------------
int(1.7) +1.0
floor(1.7) +1.0
round(1.7) +2.0
--------------------
int(-1.2) -1.0
floor(-1.2) -2.0
round(-1.2) -1.0
--------------------
int(-1.7) -1.0
floor(-1.7) -2.0
round(-1.7) -2.0
--------------------
>>>

 

阅读(865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~