|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to check whether a number is an integer?Hello,
I need to know whether the result of a division is a integer or not. dim x =60 dim y = 3 if x/y is a integer then .... else .... end if How can i know that? Thanks André If x/y = x\y then
'Is an integer else 'is not end if André wrote: Show quoteHide quote > Hello, > > I need to know whether the result of a division is a integer or not. > dim x =60 > dim y = 3 > > if x/y is a integer then > .... > else > .... > end if > > How can i know that? > Thanks > André > > Thanks
"Theo Verweij" <tverw***@xs4all.nl> schreef in bericht If x/y = x\y thennews:%231XBiNe%23GHA.4376@TK2MSFTNGP03.phx.gbl... 'Is an integer else 'is not end if André wrote: Show quoteHide quote > Hello, > > I need to know whether the result of a division is a integer or not. > dim x =60 > dim y = 3 > > if x/y is a integer then > .... > else > .... > end if > > How can i know that? > Thanks > André >
Show quote
Hide quote
"André" <s**@sdv.sd> wrote in message I would actually use Mod (modulus) to determine if a division result news:eahb7ge#GHA.4464@TK2MSFTNGP02.phx.gbl... > Thanks > > "Theo Verweij" <tverw***@xs4all.nl> schreef in bericht > news:%231XBiNe%23GHA.4376@TK2MSFTNGP03.phx.gbl... > If x/y = x\y then > 'Is an integer > else > 'is not > end if > > André wrote: >> Hello, >> >> I need to know whether the result of a division is a integer or not. >> dim x =60 >> dim y = 3 >> >> if x/y is a integer then >> .... >> else >> .... >> end if >> >> How can i know that? >> Thanks >> André >> > > (remainder) is 0. Example: Dim x As Integer = 12 Dim y As Integer = 6 Dim isInt As Boolean = x Mod y = 0 Console.WriteLine( _ "Remainder of {0} / {1} = {2} : Integral = {3}", _ x.ToString(), _ y.ToString(), _ (x / y).ToString(), _ (x Mod y = 0).ToString() _ ) The last parameter (x Mod y = 0) is the part that I would use :) So: If x Mod y = 0 Then ' x / y results in a 0 remainder, meaning an int result (given that the result falls within the scope of an integer and not a long. Else ' x / y results in a non-0 remainder, meaning a floating point result. End If HTH :) Mythran
Show quote
Hide quote
On Fri, 27 Oct 2006 18:13:27 +0200, "André" <s**@sdv.sd> wrote: If x Mod y = 0 then>Hello, > >I need to know whether the result of a division is a integer or not. >dim x =60 >dim y = 3 > >if x/y is a integer then >... >else >... >end if > >How can i know that? >Thanks >André > ' it's an integer else 'it's not an integer endif "André" <s**@sdv.sd> schrieb: 'If Int(x) = x Then...'> I need to know whether the result of a division is a integer or not. > dim x =60 > dim y = 3 > > if x/y is a integer then > ... > else > ... > end if -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Andre,
Put option strict on in top of your program, than it will divide only doubles using the non integer divide. Cor Show quoteHide quote "André" <s**@sdv.sd> schreef in bericht news:Ou8oULe%23GHA.1172@TK2MSFTNGP03.phx.gbl... > Hello, > > I need to know whether the result of a division is a integer or not. > dim x =60 > dim y = 3 > > if x/y is a integer then > ... > else > ... > end if > > How can i know that? > Thanks > André >
vb.net; controls
Adding Lines to Access Database Merging two VB.NET projects Asynchronous Socket Server Question how to put two textboxes under each other? Detecting textchanged event when user initiates it Creating a new database with limits using SMO How to Reference a .Net Assembly from within VBA? Communicate with parallel port via web interphace Starting field on a form |
|||||||||||||||||||||||