If var isnumber, for script

后端 未结 3 984
执念已碎
执念已碎 2020-12-31 05:45

I need to run a script which contains the logic: If isNumber, Then DoSomething.

I\'ve run other such if then tests such as if blank, and if cell contains \"

3条回答
  •  难免孤独
    2020-12-31 06:10

    If you want to do number stuff if the value is a number or a string representation of a number you can do the following:

    if (!isNaN(myVar)){//myVar is either a number or a string representing a number
        myNumericVar = +myVar;//convert myVar to number if necessary
        //do number stuff
    } else {
       //do non-numeric stuff
    }
    

    See:

    (Built-in) way in JavaScript to check if a string is a valid number

提交回复
热议问题