Use of IsNumeric function in VB.NET

IsNumeric() function returns a value indicating whether an expression can be converted to a numeric data type.
  • 9056

IsNumeric() function returns True if the data type of Expression is BooleanByteDecimal, etc or an Object that contains one of those numeric types, It returns a value indicating whether an expression can be converted to a numeric data type. It also returns True if Expression is a Char or String that can be successfully converted to a number.

IsNumeric returns False if Expression is of data type Date or of data type Object and it does not contain a numeric type, It has to do with the format/type of the data, not the actual value of the data.  And "NaN"  I believe is technically of type float. IsNumeric returns False if Expression is aChar or String that cannot be converted to a number.


 Class Sample
    Public Shared Sub
        Dim Data1 As String = Nothing
        Dim Output As New System.Text.StringBuilder
        Output.AppendLine(String.Format( _
           "IsNumeric({0}) ... {1}", Data1, IsNumeric(Data1)))
        Data1 = "-11.1231"
        Output.AppendLine(String.Format( _
           "IsNumeric({0}) ... {1}", Data1, IsNumeric(Data1)))
        Data1 = "October 21, 1987"
        Output.Append(String.Format( _
           "IsNumeric({0}) ... {1}", Data1, IsNothing(Data1)))

End Sub
End Class




More Articles

© 2020 DotNetHeaven. All rights reserved.