Rounding to nearest 0.25

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
 
K

Ken Snell

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
 
D

david epsom dot com dot au

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)
 
I

Ian

Ken

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

Thanks
Ian
 
K

Ken Snell

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

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Rounding to the nearest 0.25 4
Round to nearest quarter 5
Access 2007: % fields rounding to nearest integer 3
Datediff 1
Rounding up to the nearest .25 1
Excel Time Rounding in Excel 2
Rounding 10
Rounding up! 2

Top