-
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!
-
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?
-
Ceil : int(num)+1
Floor : int(num)
Hope this helps
-
oops: here is the ceil function
ceilnum = int(num) + iif((int = int(num)),0,1)
-
a typo again
ceilnum = int(num) + iif((num = int(num)),0,1)
-
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.
-
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
-
My mistake, thought you were using the CInt, not Int for the conversion!!