Convert String Float Numeral Into Float in Python

(Last Updated On: 17/02/2023)

Python Program to Convert String Float Numeral Into Float

# Convert string float numeral into float in python
 
string = '55.567'

Float = float(int(string))

print(type(Float))
print('Float Value =', Float)

Output:

(Note: we try to convert a string into an integer and then a float. In the output we can see that we can’t convert a string float number into an integer thus, we get a value error.)

Traceback (most recent call last):
  File "<string>", line 5, in <module>
ValueError: invalid literal for int() with base 10: '55.567'

Leave a Reply

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