Results 1 to 8 of 8

Thread: CEIL and FLOOR equivalent

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Manila, Philippines
    Posts
    59

    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.

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    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?
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Guest
    Ceil : int(num)+1
    Floor : int(num)

    Hope this helps


  4. #4
    Guest
    oops: here is the ceil function

    ceilnum = int(num) + iif((int = int(num)),0,1)

  5. #5
    Guest
    a typo again
    ceilnum = int(num) + iif((num = int(num)),0,1)

  6. #6
    Guest
    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.

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

  8. #8
    Guest
    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
  •  



Click Here to Expand Forum to Full Width