Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > is there any is integer function ?

Reply
Thread Tools

is there any is integer function ?

 
 
Tee
Guest
Posts: n/a
 
      02-27-2004
Hi,

how do we detect if a value is a positive integer ?

thanks,
Tee


 
Reply With Quote
 
 
 
 
TJS
Guest
Posts: n/a
 
      02-27-2004
if myValue > 0 then ...


"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:%23eHvYdO$(E-Mail Removed)...
> Hi,
>
> how do we detect if a value is a positive integer ?
>
> thanks,
> Tee
>
>



 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      02-27-2004
> how do we detect if a value is a positive integer ?

Are you using VB.NET or C#? In C# I'd do:

if (x is int)
{
if ((int) x) > 0)
// x is a positive integer
else
// x is a negative integer
}
else
// x is NOT an integer at all!


In VB.NET you can use IsNumeric().

--

Scott Mitchell
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      02-27-2004
And how would this know the difference between 1 and 1.1?

if x > 0 AND x = CTYPE(x, Integer) then


"TJS" <(E-Mail Removed)> wrote in message
news:%23M7RetO$(E-Mail Removed)...
> if myValue > 0 then ...
>
>
> "Tee" <thy[NO@SPAM]streamyx.com> wrote in message
> news:%23eHvYdO$(E-Mail Removed)...
> > Hi,
> >
> > how do we detect if a value is a positive integer ?
> >
> > thanks,
> > Tee
> >
> >

>
>



 
Reply With Quote
 
Tee
Guest
Posts: n/a
 
      02-27-2004
Hi,

Thanks for your reply,
I know about the isnumeric, but ... whatever number value will return true
with isnumeric, so I hope to get something like isInteger() ...

thanks.
Tee



"Scott Mitchell [MVP]" <(E-Mail Removed)> wrote in message
newsSz%b.30990$(E-Mail Removed). com...
>> how do we detect if a value is a positive integer ?

>
> Are you using VB.NET or C#? In C# I'd do:
>
> if (x is int)
> {
> if ((int) x) > 0)
> // x is a positive integer
> else
> // x is a negative integer
> }
> else
> // x is NOT an integer at all!
>
>
> In VB.NET you can use IsNumeric().
>
> --
>
> Scott Mitchell
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
> http://www.ASPFAQs.com
> http://www.ASPMessageboard.com
>
> * When you think ASP, think 4GuysFromRolla.com!



 
Reply With Quote
 
Tee
Guest
Posts: n/a
 
      02-27-2004
Great idea,

Thanks.


"Scott M." <(E-Mail Removed)> wrote in message
news:uidueTP$(E-Mail Removed)...
> And how would this know the difference between 1 and 1.1?
>
> if x > 0 AND x = CTYPE(x, Integer) then
>
>
> "TJS" <(E-Mail Removed)> wrote in message
> news:%23M7RetO$(E-Mail Removed)...
>> if myValue > 0 then ...
>>
>>
>> "Tee" <thy[NO@SPAM]streamyx.com> wrote in message
>> news:%23eHvYdO$(E-Mail Removed)...
>> > Hi,
>> >
>> > how do we detect if a value is a positive integer ?
>> >
>> > thanks,
>> > Tee
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Harsh Thakur
Guest
Posts: n/a
 
      02-27-2004
Hi,

As noted before, for a positive integer, you can just say:
if(x > 0)
To test whether x is in integer, you can say:
x = int.Parse(value.ToString())
where value is the number you want to check.

If value represents an integer, x will contain it after
the step given above. Else an FormatException will be
thrown.

For more details you can check out int.Parse in MSDN.

HTH
Regards
Harsh Thakur

>-----Original Message-----
>Hi,
>
>how do we detect if a value is a positive integer ?
>
>thanks,
>Tee
>
>
>.
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      02-27-2004
> with isnumeric, so I hope to get something like isInteger() ...

You need to re-read Scott's reply. That was the first thing he tested for.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:uTcdEYP$(E-Mail Removed)...
> Hi,
>
> Thanks for your reply,
> I know about the isnumeric, but ... whatever number value will return true
> with isnumeric, so I hope to get something like isInteger() ...
>
> thanks.
> Tee
>
>
>
> "Scott Mitchell [MVP]" <(E-Mail Removed)> wrote in message
> newsSz%b.30990$(E-Mail Removed). com...
> >> how do we detect if a value is a positive integer ?

> >
> > Are you using VB.NET or C#? In C# I'd do:
> >
> > if (x is int)
> > {
> > if ((int) x) > 0)
> > // x is a positive integer
> > else
> > // x is a negative integer
> > }
> > else
> > // x is NOT an integer at all!
> >
> >
> > In VB.NET you can use IsNumeric().
> >
> > --
> >
> > Scott Mitchell
> > (E-Mail Removed)
> > http://www.4GuysFromRolla.com
> > http://www.ASPFAQs.com
> > http://www.ASPMessageboard.com
> >
> > * When you think ASP, think 4GuysFromRolla.com!

>
>



 
Reply With Quote
 
JesseChallis JesseChallis is offline
Junior Member
Join Date: Jul 2010
Posts: 1
 
      07-01-2010
public bool IsNumber(string text)
{
bool result = true;
foreach (var c in text)
{
if (!Char.IsDigit(c))
{
result = false;
break;
}
}

return result;
}

Cheers
 
Reply With Quote
 
rutgers rutgers is offline
Junior Member
Join Date: Feb 2011
Posts: 1
 
      02-28-2011
Try this:


If IsNumeric(UserInputTextBox.Text) And (System.Math.Abs(val(UserInputTextBox.Text) Mod 1) <> 0) Then
'______Do something
End if

************************
OR Atfer checking IsNumeric(UserInputTextBox.Text)
Do this following:

if (System.Math.Abs(val(UserInputTextBox.Text) Mod 1) <> 0)
 

Last edited by rutgers; 02-28-2011 at 04:58 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

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
Does ModelSim or any simulator software have a function similar tothe standard function any logic analizer has? Weng Tianxiang VHDL 7 09-11-2009 04:47 PM
is there a way to AutoParse a string to another type - e.g. if aDate format then date, else if integer than Integer etc ????? Greg Hauptmann Ruby 6 08-06-2008 04:52 PM
is there a way to call a function depending on an integer at runtime? aaragon C++ 15 12-30-2007 01:28 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM



Advertisments