python除法

#-*-coding:utf-8-*-
'''
Created on 2016年3月19日

@author: Zroad
'''
#from __future__ import division

print "Hello,python3.0"

"""
一、传统除法X/Y形式:
1、py2.6:整数相除省去小数部分,浮点数相除保留小数
2、py3.0:整数相除也会保留小数部分
"""
print 3/2  #1
print 3/2 #py3.0,1.5
print 3.0/2 #1.5
print 3.0/2.0 #1.5


"""
二、Floor除法X//Y形式  等价于math.floor(x):
向下舍入,并不是严格的截断,正数总是省略后面的小数,负数结果为最近的整数
"""
print 7//4  #1
print 5//4  #1 
print 3.0//4.0 #0.0
print -5.0//2.0 #-3.0 

import math
print math.floor(1.25) #1.0
print math.floor(1.75) #1.0
print math.floor(-2.5) #-3.0
print math.floor(-2.15) #-3.0
print math.floor(-2.75) #-3.0

"""
三、截断除法:trunc(x):
无论正负,省略小数位
"""
print math.trunc(1.25) #1
print math.trunc(1.75) #1
print math.trunc(-2.75) #-2
print math.trunc(-2.15) #-2

"""
四、int(x),直接截除小数部分
"""
print "int(4.7)=",int(4.7) #4
print "int(4.2)=",int(4.2) #4
print "int(-2.7)=",int(-2.7) #-2
print "int(-2.2)=",int(-2.2) #-2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值