IsNumeric function not working correctly

I have a very strange problem with the IsNumeric function in a classic asp fail. Something like this happens in my code:

Response.write Score                // 79.617
Response.write IsNumeric(Score)     // false
Response.write IsNumeric("79.617")  // true

Anyone got an idea why this could happen?

The spec says that functions work with strings that can be converted to numbers, and from the above example you can see that I am getting a “true” result. But what can then cause my problem?

+5
source share
1 answer

This means that Score- this is simply not a string, but something else, most likely coming from the database.

To be safe, use your own function:

Function My_IsNumeric(value)
    My_IsNumeric = False
    If IsNull(value) Then Exit Function
    My_IsNumeric = IsNumeric(CStr(value))
End Function

Response.write My_IsNumeric(Score)

CStr() -, Null, , Null, , IsNull().

+9

All Articles