# MS Access use of Ceiling() function to round up and handle negative numbers similarly to positive

I'm using:
``````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
``````
but -1.28 is rounded to -1

what I need is -1.28 to round to -2

I also need 1.28 to continue to round to 2 (as it does now)

eventually, in another system that rounds up I'm having to match -1.28 to 1.28
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Try this
``````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
boolean neg=X<0
X=ABS(X)
Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
if (neg) then Ceiling =-(Ceiling )
End Function
``````
0
getting a Compile Error: Syntax Error with that.

The "boolean neg=X<0" bit is in RED if that is on any use.

I'm in Access 2007 sorry not to have noted that previously if useful.
0
Commented:
``````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
Dim neg as boolean
neg=X<0
X=ABS(X)
Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
if (neg) then Ceiling =-(Ceiling )
End Function
``````

Try that
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Sorry, I have been shuffling around in so many languages today I forget which syntax goes to which :P
0
Beautiful!
Thanks as always for the attention.
0
CIOCommented:
That is a quite complicated way to achive this when a one-liner will do:

intRounded = -Sgn(intValue) * Int(-intValue * Sgn(intValue))

/gustav
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.