17
loading...
This website collects cookies to deliver better user experience
float()
function is a built-in utility method which takes any object as an input parameter and converts into floating point number.Internally float()
function calls specified object__float__ ()
function.input= "33.455"
print(input)
print('Before conversion',type(input))
# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))
33.455
Before conversion <class 'str'>
33.455
After conversion <class 'float'>
output = float()
print(output)
# Output
# 0.0
# string with integer to float
input= "100"
print(input)
print('Before conversion',type(input))
# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))
100
Before conversion <class 'str'>
100.0
After conversion <class 'float'>
# string with integer to float
input= ".000123"
print(input)
print('Before conversion',type(input))
# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))
.000123
Before conversion <class 'str'>
0.000123
After conversion <class 'float'>
# string with integer to float
input= "1.23e-4"
print(input)
print('Before conversion',type(input))
# converting string to float
output = float(input)
print(output)
print('After conversion',type(output))
1.23e-4
Before conversion <class 'str'>
0.000123
After conversion <class 'float'>