Ceiling and floor functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hell

Is there access functions for the excel equivalent of ceiling and floor functions? By converting the number to an integer, the number is rounded down to the nearest integer (this is equivalent to a floor). How do I round up by an integer

Thanks
 
You can use the ceiling and floor functions from Excel by setting a
reference to them, Here's some similar code I posted yesterday:

Set a reference to Excel, then (aircode):

Function XLSkew(Arg1, Arg2) as Double
Dim objXL As New Excel.Application
XLSkew = objXL.WorksheetFunction.Skew(Arg1,Arg2)
Set objXL = Nothing
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Kelesh Roopram said:
Hello

Is there access functions for the excel equivalent of ceiling and floor
functions? By converting the number to an integer, the number is rounded
down to the nearest integer (this is equivalent to a floor). How do I round
up by an integer?
 
If you don't want to reference Excel,
You could have a look at the 'Round' function,

but beware, it's a bit strange:

eg
Round(6.5) = 6 - I always thought you rounded up on .5
however,
Round(6.49) = 6
Round(6.51) = 7

Int() or Fix() will always round down:

Int(4.9) = 4
Fix(4.9) = 4

They differ with -tve numbers though:

int(-8.4) = -9
int(-8.6) = -9

fix(-8.4) = 8
fix(-8.6) = 8

Cheers,


So:
fix() ~ Floor()
fix()+1 ~ Ceiling()

You would have to be careful with this if you needed to handle -tve numbers
as well, and don't forget to watch out for 0!

iif(sgn(<yourNumber>)=1,<deal with +tve numbers
here>,iif(sgn(<yourNumber)=-1,<deal with -tve numbers here>,<deal with 0
here>))


ChrisM
 
Back
Top