Search code examples
javascriptfloating-pointtypeof

How can I check to see if a value is a float in javascript


I want to check to see if my input is a float.

Sooo something like...

if (typeof (input) == "float")
do something....

What is the proper way to do this?


Solution

  • Try parseFloat

    The parseFloat() function parses an argument (converting it to a string first if needed) and returns a floating point number.

    if(!isNaN(parseFloat(input))) {
        // is float    
    }