# Rounding up to the nearest 0.25 in Access

I would like to be able to round up to the nearest 0.25 in Access.  The number I am rounding is always positive btw.  I have searched this into the ground and thought I had an answer...but something is wrong and I have no idea what to change to make it work.  I added the following module to my database...

Function RoundToNearest(dblNumber As Double, varRoundAmount As Double, _
Optional varUp As Variant) As Double

Dim dblTemp As Double
Dim lngTemp As Long

dblTemp = dblNumber / varRoundAmount
lngTemp = CLng(dblTemp)

If lngTemp = dblTemp Then
RoundToNearest = dblNumber
Else
If IsMissing(varUp) Then
' round up
dblTemp = lngTemp + 1
Else
' round down
dblTemp = lngTemp
End If
RoundToNearest = dblTemp * varRoundAmount
End If
End Function

I then put the following in my query...RoundToNearest([MyNumber],0.25).

It delivers...
2.6616 as 3.00 (should be 2.75)
2.9683 as 3.25 (should be 3.00)
2.7921 as 3.00 (ok)
2.6019 as 2.75 (ok)
3.2427 as 3.50 (should be 3.25)
2 out of 5 just doesn’t work.  What do I need to change or is there another way?

###### 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
round(yourNumber * 4,0)/4
0
Commented:
Here's another formula you can try:

=INT(4*[YourNumberField]+0.5)/4

Flyster
0
Commented:
To get the results you specified, where the value is higher than the input number (A1 is your number)

=ROUND(A1*4+0.5,0)/4
0
CIOCommented:
This works:

dblRoundedUp = -Int(-dblValue * 4) / 4
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:
Tested Gustav's comment. I prefer it as a solution. My comment fails for .5 value.
0
Author Commented:
Thanks!  I waited way too long to ask for help.  This is awesome!!
0
Commented:
KJKAccess,

did my post at http:#a40200811 failed your test?
0
Author Commented:
"Round" goes in which ever direction is closer...
So 2.76 would round to 2.75...but I need it to round up in all instances (go to 3.00 for this example)
0
CIOCommented:
You are welcome!

/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.