Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating integer routine not working 3

Status
Not open for further replies.

ShikkurDude

Programmer
Mar 15, 2005
55
US
I have the following routine for validating whether a number's an integer:
Code:
	Private Function isInteger(ByRef inputNumber As Double) As Boolean
		If inputNumber.ToString - CInt(inputNumber) <> 0 Then
			Return False
		Else
			Return True
		End If
	End Function
The problem is it returns TRUE for "9.00" and I must have any non-integer return FALSE.

Any ideas, please?

Thanks,
E.
 
9.00 is an Integer... well, I guess 9 is an integer, but mathmatically, 9=9.00

So, a few things to try.

Code:
'Check the Int divid value
if inputNumber = inputNumber \ 1 then
 'Int value
else
 'non-int value
end if

or If you need to exclude 9.00 try this:
Code:
if inputNumber.tostring.indexof(".")>=0 then
  'non-Int value
else
  'Int value
end if

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
That doesn't work. The problem with using ToString is that it converts "9.00" to "9"...

E
 
John,

I like your idea, but it still returns TRUE for "9.00" - I need that to return FALSE. Anything with a decimial must return FALSE...

Any ideas?

Thanks,
E.
 
Code:
Public Function isInteger(ByVal o As Object) As Boolean
    If IsNumeric(o) And CStr(o).IndexOf("."c) < 0 Then
        Return True
    End If
End Function


Sweep
...if it works dont mess with it
 
Sweep,

Thanks, but the same problem: it still returns TRUE for "3.00"...

E.
 
It doesn't return True for me...
Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim x As Boolean = isInteger("3.00")
        MessageBox.Show(x)
    End Sub

    Public Function isInteger(ByVal o As Object) As Boolean
        If IsNumeric(o) And CStr(o).IndexOf(".") < 0 Then
            Return True
        End If
    End Function

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top