|
-
Jan 13th, 2001, 05:06 AM
#1
Thread Starter
New Member
Does anybody know how to check if a number is whole after being divided by 2 numbers?
-
Jan 13th, 2001, 05:22 AM
#2
Fanatic Member
Use this function
Use this function to check if a number is whole. It converts the variant you pass it to a string, then checks it for a decimal point.
Code:
Private Function IsWhole(ByVal Number As Variant) As Boolean
If InStr(1, CStr(Number), ".") Then
IsWhole = False
Else
IsWhole = True
End If
End Function
'Usage
MsgBox IsWhole(32)
MsgBox IsWhole(32.5)
Hope this helps!
Later
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Jan 13th, 2001, 10:02 PM
#3
transcendental analytic
if Numeric=int(Numeric) then 'whole
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 15th, 2001, 04:34 AM
#4
Member
mod
if nbr mod int(nbr) = 0 Then Whole
Kedaman´s way seem easier, but I think this would work too.
Balder = Viking God
VB6/VC++ Enterprise Editions
-
Jan 17th, 2001, 06:39 AM
#5
Fanatic Member
There is another, quite elegant way...
If the number is whole after dividing by two then it is even originally. In Binary representation that means that the last bit will not be set - so - if x is the number then x And 1 will be 0
Code:
If (x And 1) = 0 Then
'Even number
Else
'Odd number
End If
Cheers,
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Jan 17th, 2001, 07:26 AM
#6
transcendental analytic
Off topic?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 5th, 2001, 10:24 AM
#7
Addicted Member
Kinda off topic
Here's a way to find if a number is even or not:
Function Even(Number as long) as boolean
dim a as long
dim b as long
if int(number/2) = number/2 then
even=true
else
even = false
end if
end function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|