Hi there,
can ya tell me whether there is ceiling and/or floor function in VB?
thx
Regards
ES
Printable View
Hi there,
can ya tell me whether there is ceiling and/or floor function in VB?
thx
Regards
ES
What do u mean ceiling and floor? Do u mean the Max and Min in some data?
damn u lost me there speedsolo... what do u mean ?
There's a floor, just cast it to a type that doesn't support decimals:
VB Code:
Const xWithDecimals As Double = 3.14159 Dim xWithoutDecimals As Long xWithoutDecimals = CLng(xWithDecimals) Msgbox "Before: " & xWithDecimals & vbCrLf & "After: " & xWithoutDecimals
Floor rounds a number down, Ceiling rounds a number up.Quote:
Originally posted by peet
damn u lost me there speedsolo... what do u mean ?
Well heres a ceiling function then...
VB Code:
Function Ceiling(n As Double) As Long If Not Int(n) = n Then Ceiling = Int(n) + 1 Else Ceiling = n End If End Function
eg
Ceiling(1.5) = 2
Floor(1.5) = 1
and thanks filburt1 for your suggestion, I will try it out later
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