Nate Pet Nate Pet - 1 year ago 108
Javascript Question

How can I check if a string is a float?

I am passing in a parameter called value. I'd like to know if value is a float.
So far, I have the following:

if (!isNaN(value))
alert('this is a numeric value but not sure if it is a float.');

How do I go one step further and convert the string to something that can evaluate to a float?

Answer Source

Like this:

if (!isNaN(value) && value.toString().indexOf('.') != -1)
    alert('this is a numberic value and I\'m sure it is a float.');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download