frimy
asked on
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
thanks in advance
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
thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Rounding to the nearest quarter would return these results:
For all sorts of rounding, see VBA.Round.
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.
ASKER
Daniel,
your solution works beautiful,
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
your solution works beautiful,
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
what can we [you] do?Use Daniel's code as originally posted ...
ASKER
i can do to add Abs()
i did use the same code as posted
i just want to know what Daniel can do.
i did use the same code as posted
i just want to know what Daniel can do.
I did use the same code as postedWell, look again, this time carefully.
You cannot apply Abs, as that will prohibit the rounding of negative values.
My original code included a - at the beginning that you missed which addresses this issue.
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).
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).
https://www.experts-exchange.com/questions/20447125/Rounding-to-the-nearest-quarter-hour-in-an-access-report.html