Answers for "check if string can be cast to float in python"

1

python int string float

string = "3.5"
#integer = int(string) will not work, as that returns an error.
integer = int(float(string)) #This will work, as you first turn "3.5" to 3.5
                                     #then make it the integer 3
Posted by: Guest on November-11-2021
1

check if can convert to float python

try:
    float(element)
except ValueError:
    print "Not a float"
Posted by: Guest on May-21-2020

Code answers related to "check if string can be cast to float in python"

Python Answers by Framework

Browse Popular Code Answers by Language