+2 votes
in Programming Languages by (56.5k points)

Lets say x='1.34'. How can I check if the string x is a floating point number? 

The isnumeric() function does not work for float numbers.

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

Since there is a decimal point in the string, the isnumeric() function will return False. You can replace '.' with '0' to apply the isnumeric() function.

Here is an example:

>>> x='1.34'
>>> x.replace('.','0').isnumeric()
True


...