J
James A. Fortune
Arvin said:Just saw this thread. Here's one I've been using for more than 10 years that
rounds any amount in any direction:
Option Compare Database
Option Explicit
Public Const vb_roundup = 1
Public Const vb_rounddown = 0
Function Rnd2Num(Amt As Variant, RoundAmt As Variant, _
Direction As Integer) As Double
On Error Resume Next
If Direction = vb_rounddown Then
Rnd2Num = Int(CDec(Amt) / RoundAmt) * RoundAmt
Else
Rnd2Num = -Int(CDec(-Amt) / RoundAmt) * RoundAmt
End If
End Function
?Rnd2Num(1.09,.25,1)
1.25
Arvin,
The fact that you've used -Int(-X) for rounding up for over 10 years
suggests the possibility that Van T. Dinh borrowed that idea from
someone else many years ago.
C.f.:
http://groups.google.com/group/microsoft.public.access/msg/9614be58d0485dd0
and
http://groups.google.com/group/comp.databases.ms-access/msg/4b3e8b87e0ede4e4
Do you have any idea who discovered that gem originally? The level of
cleverness required to discover that is beyond what I see typically in
the newsgroups .
James A. Fortune
(e-mail address removed)