Rounding to nearest 0.25

  • Thread starter Thread starter Ian
  • Start date Start date
I

Ian

Is it possible to round to the nearest 0.25 ?
This will be used in a total time field where I need to
round to the nearest quarter hour.

Thanks
 
I assume that you mean
4.13 rounds to 4.25
4.28 rounds to 4.25
4.12 rounds to 4.00
4.92 rounds to 5.00

This expression should get you pretty close:

(((MyNumber * 100) + 12.1) \ 25) / 100 * 25
 
In A2K and later versions:

=Round(v * 4)/4

This will give variable answers around the odd 8ths of the hour
(7.5 minutes, 22.5 minutes, 37.5 minutes and 52.5 minutes) but
is ok otherwise - anything you do with exact minutes should be
alright.

The variation is due to rounding errors in the binary
representation, combined with technical details of the
implementation of Bankers Rounding used by Round.

NOTE that this will only give you 1/4 hours if V is fractional
hours to start with. VB/Access times are fractional DAYS, so
if you are starting with a time value you might consider using
something like this:
dtval =round(dtval * 4 * 24) /(4 * 24)

(david)
 
Ken

Your expression works perfectly but I'm just curious,
what does the "\" symbol do in the calculation?

Thanks
Ian
 
The \ character is the operator for "integer division". It divides two
numbers and then truncates the answer to the integer portion only.

Examples:
5 \ 2 = 2 (from truncation of 2.5)

11 \ 3 = 3 (from truncation of 3.67)

etc.
 
How does the 12.1 work into the equation?, i have a similar problem except i
am rounding to the nearest mutliples of 5.
 
Back
Top