|
-
Sep 21st, 2000, 09:52 PM
#1
Thread Starter
Member
It has been quite a while that i've been looking for a function in VB which is the equivalent of CEIL or FLOOR in C. I have to make a function to complement CEIL and FLOOR. Is there anybody there who knows what VB Function is the counterpart of the two? I've checked Int and Fix but it seems to complement only the FLOOR function.
thanks!
Mikey
A/P
Using VB6 SP4 Enterprise Ed.
-
Sep 22nd, 2000, 04:38 AM
#2
Frenzied Member
I won't pretend to know what CEIL and FLOOR do, but I have a hunch I may know just the function. What exactly do CEIL and FLOOR perform?
-
Sep 22nd, 2000, 09:22 AM
#3
Ceil : int(num)+1
Floor : int(num)
Hope this helps
-
Sep 22nd, 2000, 11:09 AM
#4
oops: here is the ceil function
ceilnum = int(num) + iif((int = int(num)),0,1)
-
Sep 22nd, 2000, 11:10 AM
#5
a typo again
ceilnum = int(num) + iif((num = int(num)),0,1)
-
Sep 22nd, 2000, 11:50 AM
#6
For CEIL can't you just do:
f(y) = CLng (y + 0.5)
This should get the number above Y
ie f(0.5) = 1
f(0.9) = 1
f(0) = 0
and for Floor...
f(y) = Fix(y)
f(1.1) = 1
f(1.9) = 1
using int(num) will not return the same as floor in C
as it will round numbers up if over 0.5 on the fration part.
-
Sep 22nd, 2000, 11:55 AM
#7
This is from MSDN:
Dim MyNumber
MyNumber = Int(99.8) ' Returns 99.
MyNumber = Fix(99.2) ' Returns 99.
MyNumber = Int(-99.8) ' Returns -100.
MyNumber = Fix(-99.8) ' Returns -99.
MyNumber = Int(-99.2) ' Returns -100.
MyNumber = Fix(-99.2) ' Returns -99.
Unless the number is negative, int will not round numbers up if over 0.5 on the fration part
-
Sep 22nd, 2000, 11:58 AM
#8
My mistake, thought you were using the CInt, not Int for the conversion!!
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
|