How can I check if a string is a float?

前端 未结 14 1804
清歌不尽
清歌不尽 2020-12-23 20:21

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 num         


        
14条回答
  •  遥遥无期
    2020-12-23 20:47

    Like this:

    if (!isNaN(value) && value.toString().indexOf('.') != -1)
    {
        alert('this is a numeric value and I\'m sure it is a float.');
    }​
    

提交回复
热议问题