Jan 14, 2016 09:13 PM|anjaliagarwal5@yahoo.com|LINK
Hi All,
I am checking in my code if the line is numeric then do this otherwise do something else.
if IsNumeric(line) = true then
' do something
else
'do something else
some of the numbers that have 2. or 3., they are considered to be numeric. Is there any way, I can check that they are not numeric since they are suffixed by a period.
I tried doing this:
If IsNumeric(line)= False Or line.Substring(1, 1) = "." Then
do soemthing
It does not seem to be that robust solution. Is there any other way, I can check for only numeric values. If there is a period or any other character
then it won't be considered as numeric.
any help will be appreciated.
Update: I think I got it. I just have to do Integer.TryParse and that will only give integer values.
I would suggest Decimal.TryParse for example. I don't know if 2. would pass but at least you have the guarantee that the string can be converted to a numeric value). Note also that the result dépends on which culture is used.
some of the numbers that have 2. or 3., they are considered to be numeric. Is there any way, I can check that they are not numeric since they are suffixed by a period.
IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number. You could use the following code to meet your requirement.
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim testVar As Object
testVar = "53"
testVar = "459.95"
'testVar = "45 Help"
If Not IsNumeric(testVar) Or testVar.ToString.Contains(".") Then
TextBox1.Text = "NotIsNumeric"
Else
TextBox1.Text = "IsNumeric"
End If
End Sub
End Class
Member
511 Points
1275 Posts
isnumeric function in VB.net
Jan 14, 2016 09:13 PM|anjaliagarwal5@yahoo.com|LINK
Hi All,
I am checking in my code if the line is numeric then do this otherwise do something else.
if IsNumeric(line) = true then
' do something
else
'do something else
some of the numbers that have 2. or 3., they are considered to be numeric. Is there any way, I can check that they are not numeric since they are suffixed by a period.
I tried doing this:
It does not seem to be that robust solution. Is there any other way, I can check for only numeric values. If there is a period or any other character then it won't be considered as numeric.
any help will be appreciated.
Update: I think I got it. I just have to do Integer.TryParse and that will only give integer values.
All-Star
48570 Points
18082 Posts
Re: isnumeric function in VB.net
Jan 14, 2016 09:26 PM|PatriceSc|LINK
Hi,
I would suggest Decimal.TryParse for example. I don't know if 2. would pass but at least you have the guarantee that the string can be converted to a numeric value). Note also that the result dépends on which culture is used.
Star
8460 Points
1445 Posts
Re: isnumeric function in VB.net
Jan 15, 2016 06:24 AM|Klein Zhang|LINK
Hi anjaliagarwal5,
IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number. You could use the following code to meet your requirement.
I hope it's helpful to you.
Best Regards,
Klein zhang