PC Review


Reply
Thread Tools Rate Thread

how to determine if numeric data contains a decimal?

 
 
=?Utf-8?B?UmljaA==?=
Guest
Posts: n/a
 
      20th Feb 2007
Is there a way to determine if a numeric value contains a decimal? how to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich


 
Reply With Quote
 
 
 
 
rowe_newsgroups
Guest
Posts: n/a
 
      20th Feb 2007
On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.com> wrote:
> Is there a way to determine if a numeric value contains a decimal? how to do
> this?
>
> If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
> value. How can I tell if it is a plain integer or decimal?
>
> Thanks,
> Rich


Parse the string for a period using IndexOf.

<pseudocode>

if IsNumeric(txt1.Text) then
if txt1.IndexOf(".") <> -1 then
' Decimal
else
' Integer
end if
end if

</pseudocode>

Thanks,

Seth Rowe



 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      20th Feb 2007
rowe_newsgroups wrote:
> On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.com> wrote:
>> Is there a way to determine if a numeric value contains a decimal? how to do
>> this?
>>
>> If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
>> value. How can I tell if it is a plain integer or decimal?
>>
>> Thanks,
>> Rich

>
> Parse the string for a period using IndexOf.
>
> <pseudocode>
>
> if IsNumeric(txt1.Text) then
> if txt1.IndexOf(".") <> -1 then
> ' Decimal
> else
> ' Integer
> end if
> end if
>
> </pseudocode>
>
> Thanks,
>
> Seth Rowe
>
>
>


That's assuming that the decimal separator is a period, which it isn't
everywhere.

The decimal separator for any given culture can be found in the
NumberFormat.NumberDecimalSeparator property.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Paul Evans
Guest
Posts: n/a
 
      20th Feb 2007
"Göran Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> rowe_newsgroups wrote:
>> On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.com> wrote:
>>> Is there a way to determine if a numeric value contains a decimal? how
>>> to do
>>> this?
>>>
>>> If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a
>>> numeric
>>> value. How can I tell if it is a plain integer or decimal?
>>>
>>> Thanks,
>>> Rich

>>
>> Parse the string for a period using IndexOf.
>>
>> <pseudocode>
>>
>> if IsNumeric(txt1.Text) then
>> if txt1.IndexOf(".") <> -1 then
>> ' Decimal
>> else
>> ' Integer
>> end if
>> end if
>>
>> </pseudocode>
>>
>> Thanks,
>>
>> Seth Rowe
>>
>>
>>

>
> That's assuming that the decimal separator is a period, which it isn't
> everywhere.
>
> The decimal separator for any given culture can be found in the
> NumberFormat.NumberDecimalSeparator property.
>
> --
> Göran Andersson
> _____
> http://www.guffa.com


Couldn't you also do something along the lines of:

If IsNumeric(txt1.Text) Then
If CLng(txt1.Text) / 1 = CLng(txt1.Text) \ 1 Then
'Integer
Else
'Decimal
End If
End If

Or, if you're doing this a lot and making a decision based on it...

Public Function IsReal (ByVal Number As Object) As Integer
Dim i As Integer
i = -1 'Fail
If IsNumeric(Number) Then
If CLng(Number) / 1 = CLng(Number) \ 1 Then
i = 0 'Integer
Else
i = 1 'Real
End If
End If
Return i
End Function

If IsReal(txt1.Text) < 1 Then MessageBox.Show("I want a real!!!")
If IsReal(txt2.Text) <> 0 Then MessageBox.Show("I want an integerl!!!")

I've just realised that this wouldn't work for "4.000000", but I'll let you
have it anyway. :\

 
Reply With Quote
 
=?Utf-8?B?UmljaA==?=
Guest
Posts: n/a
 
      20th Feb 2007
I guess there is no builtin mechanism for doing this. I really meant to
ask if there was a builtin mechanism for doing this. Appears not.

Thanks all for your replies.


"Rich" wrote:

> Is there a way to determine if a numeric value contains a decimal? how to do
> this?
>
> If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
> value. How can I tell if it is a plain integer or decimal?
>
> Thanks,
> Rich
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug? Export to text file drops numeric data right of the decimal =?Utf-8?B?QW5kcmV3?= Microsoft Access External Data 3 10th Dec 2005 09:52 PM
Error converting data type numeric to decimal? Chris Ashley Microsoft ADO .NET 1 25th Nov 2005 02:17 PM
Aligning Decimal Points with non-numeric data =?Utf-8?B?bm90bG9pc2V3ZWlzcw==?= Microsoft Excel Misc 3 11th Nov 2005 10:17 PM
Determine if a character is numeric or non-numeric AP Microsoft Excel Programming 2 11th May 2005 09:37 AM
Determine if a character is numeric or non-numeric AP Microsoft Excel Programming 2 10th May 2005 09:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 PM.