Created
December 6, 2013 08:45
-
-
Save rtDNVdza/7820573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import math | |
print "2/2=1 == " , 2/2 | |
print "3/2=1.5 == " , 3/2 | |
print "6/5=1.2 == " , 6/5 | |
print "1.2/10=0.12 == " , 1.2/10 | |
print "1.2/0.01=120 == " , 1.2/0.01 | |
print "1.0/1.0=1 == " , 1.0/1.0 | |
print "-------取小数-------" # 据说 P3 可以直接取小数 , P2 规则是整数相除得出整数 | |
print "float(3/2)=1.5 == " , float(3/2) | |
print "float(3)/2=1.5 == " , float(3)/2 | |
print "3/float(2)=1.5 == " , 3/float(2) | |
print "float(3)/float(2)=1.5 == " , float(3)/float(2) | |
print "-------四舍五入-------" | |
print "round(1.5)=2 == " , round(1.5) | |
print "round(3/2)=1.5=2 == " , round(3/2) | |
print "round(float(3)/2)=1.5=2 == " , round(float(3)/2) | |
print "round(1.2)=1 == " , round(1.1) | |
print "round(6/5)=1.2=1 == " , round(6/5) | |
print "round(float(6)/5)=1.2=1 == " , round(float(6)/5) | |
print "--------进一法,有小数就进1取整-------","需要先 import math" | |
print "math.ceil(1.5)=2 == " , math.ceil(1.5) | |
print "math.ceil(1.1)=2 == " , math.ceil(1.1) | |
print "math.ceil(3/2)=1.5=2 == " , math.ceil(3/2) # 这样是取不到的 要学下面 | |
print "math.ceil(float(3)/2)=1.5=2 == " , math.ceil(float(3)/2) | |
print "-------进一法,方法2" | |
print "UP(A/B) = int((A+B-1)/B)" | |
print "3/2=1.5=2 >> int( (3+2-1)/2 ) == " , int( (3+2-1)/2 ) # 这个方法就不用老是 float() 了 | |
print "6/5=1.2=2 >> int( (6+5-1)/2 ) == " , int( (6+5-1)/5 ) # 问题是这个方法怎么个意思 , 为什么会这样? | |
print "-------小数取整数部分------" | |
print "int(1.5),int(1.2) == " , int(1.5) , "," , int(1.2) | |
print "int(3/2),int(6/5) == " , int(3/2) , "," , int(6/5) # 这里常量都是整数 , 所以变的没有意义 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment