round function in VBA
-
Hy everyone! I do have the following situation
DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2
VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan. -
Hy everyone! I do have the following situation
DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2
VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan.I just found out myself. it's the int() function in VBA Stephan.
-
Hy everyone! I do have the following situation
DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2
VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan.Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double ' X is the value you want to round ' is the multiple to which you want to round Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor End Function Public Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double ' X is the value you want to round ' is the multiple to which you want to round Floor = Int(X / Factor) * Factor End Function