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?
I wrote functions which accept strings, integers and floats
example ouptuts:
Like this:
Then you can
Values like
2.00
cannot really be considered float in JS, or rather every number is a float in JS.EDIT: Forgot to mention that extending the prototypes of built-in types is considered a bad parctice (for a good reason) and its use is discouraged in production environments. You could still implement this check as a plain function
use this jquery code
You can use the parseFloat function.
If the value passed is a float, the function returns the value, otherwise it will return NaN.
Something like:
To check if a string is an integer or a float