Python readings – Float

print 0.12345555+0.4321
a = 0.1
print type(a)
b = 10
print type(b)
print b
print("Converting int to float")
b = float(b)
print type(b)
print b
0.55555555
<type 'float'>
<type 'int'>
10
Converting int to float
<type 'float'>
10.0
print "Value of PI is "+ repr(math.pi)
piVal = math.pi
print type(piVal)
piprecise = "%.5f"%piVal
print piprecise
print type(piprecise)
piprecise = float(piprecise)
print piprecise
print type(piprecise)
Value of PI is 3.141592653589793
<type 'float'>
3.14159
<type 'str'>
3.14159
<type 'float'>
piRound = round(math.pi,5)
print piRound
print type(piRound)
3.14159
<type 'float'>

Leave a Reply

Your email address will not be published. Required fields are marked *