Rounding to the nearest 0.25

G

Guest

Hi,

In my database I have something called a "Full Time Equivalent" - total
hours / 36.

After dividing the hours by 36 I need to round up or down to the nearest 0.25.

Thanks
 
A

Arvin Meyer [MVP]

Try this:

Function RoundTo(dblIn As Double, Optional nearest As Variant) As Double
On Error Resume Next
If IsNumeric(dblIn) Then
If IsMissing(nearest) Then nearest = 0.01
RoundTo = Int(dblIn / nearest + 0.5) * nearest
Else
RoundTo = 0
End If
End Function

Supply the field and value to round to:

RoundTo(([Full Time Equivalent]-[Total Hours]/36), 0.25)

You can use it in a query, or as a controlsource of a text box.
 
G

Guest

Sorry, I wasn't being clear. The FTE is equal to the [total hours]/36 and I
want to round the division to the nearest 0.25.

Do I put the function into a module?

Arvin Meyer said:
Try this:

Function RoundTo(dblIn As Double, Optional nearest As Variant) As Double
On Error Resume Next
If IsNumeric(dblIn) Then
If IsMissing(nearest) Then nearest = 0.01
RoundTo = Int(dblIn / nearest + 0.5) * nearest
Else
RoundTo = 0
End If
End Function

Supply the field and value to round to:

RoundTo(([Full Time Equivalent]-[Total Hours]/36), 0.25)

You can use it in a query, or as a controlsource of a text box.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

scubadiver said:
Hi,

In my database I have something called a "Full Time Equivalent" - total
hours / 36.

After dividing the hours by 36 I need to round up or down to the nearest
0.25.

Thanks
 
A

Arvin Meyer [MVP]

Yes, put it in a module. Remember, you cannot name the module the same as
the function. The corrected call would look like:

RoundTo(([Total Hours]/36), 0.25)

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

scubadiver said:
Sorry, I wasn't being clear. The FTE is equal to the [total hours]/36 and
I
want to round the division to the nearest 0.25.

Do I put the function into a module?

Arvin Meyer said:
Try this:

Function RoundTo(dblIn As Double, Optional nearest As Variant) As Double
On Error Resume Next
If IsNumeric(dblIn) Then
If IsMissing(nearest) Then nearest = 0.01
RoundTo = Int(dblIn / nearest + 0.5) * nearest
Else
RoundTo = 0
End If
End Function

Supply the field and value to round to:

RoundTo(([Full Time Equivalent]-[Total Hours]/36), 0.25)

You can use it in a query, or as a controlsource of a text box.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

scubadiver said:
Hi,

In my database I have something called a "Full Time Equivalent" - total
hours / 36.

After dividing the hours by 36 I need to round up or down to the
nearest
0.25.

Thanks
 
G

Guest

Brilliant! :)


Arvin Meyer said:
Yes, put it in a module. Remember, you cannot name the module the same as
the function. The corrected call would look like:

RoundTo(([Total Hours]/36), 0.25)

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

scubadiver said:
Sorry, I wasn't being clear. The FTE is equal to the [total hours]/36 and
I
want to round the division to the nearest 0.25.

Do I put the function into a module?

Arvin Meyer said:
Try this:

Function RoundTo(dblIn As Double, Optional nearest As Variant) As Double
On Error Resume Next
If IsNumeric(dblIn) Then
If IsMissing(nearest) Then nearest = 0.01
RoundTo = Int(dblIn / nearest + 0.5) * nearest
Else
RoundTo = 0
End If
End Function

Supply the field and value to round to:

RoundTo(([Full Time Equivalent]-[Total Hours]/36), 0.25)

You can use it in a query, or as a controlsource of a text box.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Hi,

In my database I have something called a "Full Time Equivalent" - total
hours / 36.

After dividing the hours by 36 I need to round up or down to the
nearest
0.25.

Thanks
 

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

Top