How to check if a string is a float with JavaScript?

To check if a string is a float with JavaScript, we can use the isNaN function.

For instance, we write

if (!isNaN(value) && value.toString().includes(".")) {
  console.log("this is a float.");
}

to check if value is a number by negating the boolean returned by isNaN.

And then we check if a decimal point is included by converting value to a string with toString and call the includes method on the string.

If both are true, then value is a float.