I have very strange problem with IsNumeric function in 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
Has anyone had an idea why this could happen?
In the specifications it is said that the functions works with strings that can be converted into numbers, and from the example above you can see i get "true" result. But what can then cause my issue?
Avoid using the IsNumeric() function, because it can often lead to data type conversion errors, when importing data. On SQL Server 2012 or later, use the Try_Convert() or Try_Cast() function instead. On earlier SQL Server versions, the only way to avoid it is by using LIKE expressions.
Returns a Boolean value indicating whether an expression can be evaluated as a number. The required expressionargument is a Variant containing a numeric expression or string expression. IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False.
Using ISNUMERIC() function and getting the output. Here, 0 is returned as output as the stated expression is not numeric. Example-3 : Using ISNUMERIC() function and getting the output using a variable.
The ISNUMERIC() function tests whether an expression is numeric. This function returns 1 if the expression is numeric, otherwise it returns 0.
This means Score
is simply not a string but rather something else, most likely coming from database.
To be on the safe side, 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)
The CStr()
will make sure to convert anything except Null to a string, and to handle Null coming from database you have the IsNull()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With