RE: Rounding to nearest .00 or .50

From: Sprinks (Sprinks_at_discussions.microsoft.com)
Date: 03/22/05


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



Relevant Pages

  • Rounding to nearest .00 or .50
    ... a course by dividing the total number of minutes of course instruction by 60 ... but I can only round to the nearest whole or either get the exact ...
    (microsoft.public.access.forms)
  • Re: Fastcode RoundTo
    ... The rounding control could be like the following: ... {Round to nearest else to even digit. ... drHalfOdd, {Round to nearest else to odd digit. ...
    (borland.public.delphi.language.basm)
  • Re: Win32Forth & negative zero
    ... >>>Round to nearest/even is not necessarily better than others. ... nearest with even tie breakers "IEEE rounding", ... has four rounding modes, labeled in C99 as FE_TONEAREST, ... In particular C99, which I think is getting it right, and ought ...
    (comp.lang.forth)
  • Re: Hillary Clinton Gives Driving Advice
    ... would have to do would be to round to the nearest $0.1 instead. ... The gov't has tried that on the one with issuing the dollar coin (the ... "When you can't afford the gas to drive to the job ...
    (rec.autos.driving)
  • Re: Burette/Thermom. Readings - Rounding?
    ... >I realised I don't know how to round values from thermometers, burettes ... then you round DOWN to 20.00; else if it is above the halfway ... >to the upper or lower regions inbetween the divisions. ... You have decided to read to the nearest 5 in the last ...
    (sci.chem)

Quantcast