RE: Rounding to nearest .00 or .50
From: Sprinks (Sprinks_at_discussions.microsoft.com)
Date: 03/22/05
- Next message: Owais: "Preventing data to be changed in forms"
- Previous message: micah jardine via AccessMonster.com: "RE: Basic Form query (am sure answer is simple)"
- In reply to: DTenhue: "Rounding to nearest .00 or .50"
- Next in thread: DTenhue: "RE: Rounding to nearest .00 or .50"
- Reply: DTenhue: "RE: Rounding to nearest .00 or .50"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Mar 2005 06:51:04 -0800
Access doesn't provide this functionality, but you can easily write your own
function, which you can either place in the form module, or since it is a
more general function, in a standalone application module (Module tab, New).
If you do the latter, you will need do declare it as a Public function as
shown below:
Public Function MyRounding(sglRawNumber As Single) As Single
Select Case sglRawNumber - Int(sglRawNumber)
Case Is >= 0.75
MyRounding = Int(sglRawNumber) + 1
Case Is < 0.25
MyRounding = Int(sglRawNumber)
Case Else
MyRounding = Int(sglRawNumber) + 0.5
End Select
End Function
Then set your textbox control source and/or calculated query field to the
function, passing the calculation as a parameter. Somehow you will need to
check for nulls or the function will return an error. Below is one option
using the IIf function:
=IIf(Not IsNull([txtRawNumber]) And Not
IsNull([txtDivisor]),MyRounding([txtRawNumber]/[txtDivisor]),"")
Hope that helps.
Sprinks
"DTenhue" wrote:
> I have a form in which a particular field is determining the credit hours for
> a course by dividing the total number of minutes of course instruction by 60
> minutes (in some instances, 50 minutes, depending on the state). However, I
> need the decimal number to round to the nearest half (either .00 or .50
> ONLY), but I can only round to the nearest whole or either get the exact
> number. For instance....660 minutes divided by a 50-minute hour is 13.20,
> but I need it to round to the nearest .00 which, in this instance should be
> 13.00. Please help.
>
- Next message: Owais: "Preventing data to be changed in forms"
- Previous message: micah jardine via AccessMonster.com: "RE: Basic Form query (am sure answer is simple)"
- In reply to: DTenhue: "Rounding to nearest .00 or .50"
- Next in thread: DTenhue: "RE: Rounding to nearest .00 or .50"
- Reply: DTenhue: "RE: Rounding to nearest .00 or .50"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|