Results 1 to 8 of 8

Thread: Ceiling and Floor Function?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Posts
    24

    Question Ceiling and Floor Function?

    Hi there,

    can ya tell me whether there is ceiling and/or floor function in VB?

    thx

    Regards
    ES

  2. #2
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    What do u mean ceiling and floor? Do u mean the Max and Min in some data?
    You just proved that sig advertisements work.

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    damn u lost me there speedsolo... what do u mean ?
    -= a peet post =-

  4. #4
    There's a floor, just cast it to a type that doesn't support decimals:
    VB Code:
    1. Const xWithDecimals As Double = 3.14159
    2. Dim xWithoutDecimals As Long
    3. xWithoutDecimals = CLng(xWithDecimals)
    4. Msgbox "Before: " & xWithDecimals & vbCrLf & "After: " & xWithoutDecimals

  5. #5
    Originally posted by peet
    damn u lost me there speedsolo... what do u mean ?
    Floor rounds a number down, Ceiling rounds a number up.

  6. #6
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Well heres a ceiling function then...
    VB Code:
    1. Function Ceiling(n As Double) As Long
    2.     If Not Int(n) = n Then
    3.         Ceiling = Int(n) + 1
    4.     Else
    5.         Ceiling = n
    6.     End If
    7. End Function
    You just proved that sig advertisements work.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Posts
    24
    eg
    Ceiling(1.5) = 2
    Floor(1.5) = 1

    and thanks filburt1 for your suggestion, I will try it out later

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Posts
    24
    Just tried filburt1's code but there's some problem. Found in MSDN:

    When the fractional part is exactly 0.5, CInt and CLng always round it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.

    then I moved to nishantp's and it seems fine.

    anyway, thanks v.much, you guys

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