Re: IsNumeric not returning correctly
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 8 Feb 2006 12:33:51 -0500
This is a special case. IsNumeric will correctly interpret scientific
notation, or VB's version of it, so 1E6 gets interpreted as 1,000,000 (1 *
10 ^ 6). Since that's numeric, IsNumeric returns True.
The only way I can think of to get around this is to do something like this:
Private Function IsReallyNumeric(ByVal s as String)
IsReallyNumeric = IsNumeric(Replace(s,"e","z"))
End Function
Rob
"Nathan Truhan" <ntruhan@xxxxxxxxxxxxx> wrote in message
news:CD1B59E2-B2D8-4524-AAA1-DB0EA4FC83E4@xxxxxxxxxxxxxxxx
All,
I think I may have uncovered a bug in the IsNumeric function.
I am writing a Schedule Of Classes Application for our campus and have a
seciton that lists the Times, Buildings and rooms for courses.
In this section I check if the value is numeric so I can strip off leading
0's on rooms to make it more readable. if I specify it.
The function looks like:
Private Function IsNumeric2(ByVal sString) As Boolean
If Len(sString) = 0 Then Return False
Dim bNumber As Boolean = True
Dim iInt As Integer
For iInt = 1 To Len(sString)
bNumber = bNumber And IsNumeric(Mid(sString, iInt, 1))
If bNumber = False Then Exit For
Next
Return bNumber
End Function
And performs the IsNumeric on each character in the string and bails if it
is false early. this fixes the bug so that 0E200 returns false like I and
possibly others would.
Private Function PaddCell(ByVal sValue As String, ByVal PaddCount
As
String, Optional ByVal StripNumeric As Boolean = False) As String
Dim tString As String = sValue
If StripNumeric And IsNumeric(tString) Then
tString = CStr(CInt(tString))
While Left(tString, 1) = "0"
tString = Mid(tString, 2)
End While
End If
Dim i As Integer = Len(tString)
Dim j As Integer
For j = i + 1 To PaddCount
tString += " "
Next
Return tString
End Function
the problem I have found is that if I have a room that starts with #E##,
where # is a number, such as 0E202, 1E100, or 0E500, IsNumeric returns
this
value as true!. I have tested this in .NET 2.0. I am not sure if it
occurs
in 1.1. To work around the problem, I had to write a function, which I
call
IsNumeric2:
Was this a known bug somewhere that I missed, or is this a special case I
may not be aware of. Note in the PaddCell function, the tString is being
passed as a string value, not numeric so IsNumeric should treat it as a
string I would think and not something in Scientific Notation, which is
the
only use of E I could think of.
Thanks,
Nathan
.
- Follow-Ups:
- Re: IsNumeric not returning correctly
- From: Bob Butler
- Re: IsNumeric not returning correctly
- Prev by Date: Re: IsNumeric not returning correctly
- Next by Date: Re: IsNumeric not returning correctly
- Previous by thread: Re: IsNumeric not returning correctly
- Next by thread: Re: IsNumeric not returning correctly
- Index(es):
Relevant Pages
|
Loading