Velocity Reviews > is there any is integer function ?

# 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

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
>
>

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!

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
> >
> >

>
>

Tee
Guest
Posts: n/a

 02-27-2004
Hi,

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!

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
>> >
>> >

>>
>>

>
>

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
>
>
>.
>

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
of lots of little things.

"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:uTcdEYP\$(E-Mail Removed)...
> Hi,
>
> 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!

>
>

JesseChallis
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

rutgers
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..