Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

ValueError: could not convert string to float

Occurs when a string cannot be converted to a float.

Reproduce

value = "abc"
number = float(value)

Error Message

Traceback (most recent call last):
  File "reproduce.py", line 2, in <module>
    number = float(value)
ValueError: could not convert string to float: 'abc'

Fix

value = "12.3"
number = float(value)
print(number)

Output

12.3

Reflection

float() only works with numeric strings.