# how to round to the nearest .25 (quarter)

Hello ALL!
how to round to the nearest quarter .25
i.e.
1.20 =  1.25
1.30 =  1.50
1.65 =  1.75
1.80 =  2.00

Microsoft Access

Last Comment
noci
Gerwin Jansen

Daniel Pineault

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Gustav Brock

Rounding to the nearest quarter would return these results:

`````` 1.2           1.25
1.3           1.25
1.65          1.75
1.8           1.75
``````
which can be reached using Format:

``````RoundedAmount = CCur(Format(Amount * 4, "0")) / 4
``````
However, your example values show values rounded up. That can be done using Daniel's expression.

For all sorts of rounding, see VBA.Round.
frimy

Daniel,
but one problem, it adds a minus sign before the number.

a = 33.60
b = Int(-a * 4) / 4
b = -33.75

what can we do?
thanks

Gustav Brock

what can we [you] do?
Use Daniel's code as originally posted ...
frimy

i can do to add Abs()
i did use the same code as posted
i just want to know what Daniel can do.

Gustav Brock

I did use the same code as posted
Well, look again, this time carefully.

You cannot apply Abs, as that will prohibit the rounding of negative values.
Daniel Pineault

My original code included a - at the beginning that you missed which addresses this issue.
noci

Be aware of the domain used. If you multiply a value by 4  you should not overflow the values.
Also be aware of rounding behaviour...    multiply by 4  device by 4 is a binary neutral operation (shift left2, shitft right 2 bits).

With non 2^n numbers you introduce more rounding due to "non-fitting" data (there is no 1/3rd bit).

Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY