I have tried using a RoundAU function from the KB of Microsoft but it does
not help.
Any ideas????
Thanks,
Allan Bach
ab...@ptd.net
?dhRound(234.4567,2)
234.46
Function dhRound(dblNumber As Double, intDecimals _
As Integer) As Double
' Rounds a number to a specified number of decimal
' places. 0.5 is rounded up
' From "VBA Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 1997; Sybex, Inc. All rights reserved.
' In:
' dblNumber:
' The number to be rounded
' intDecimals:
' The number of decimal places to round to
' Out:
' Return Value:
' The rounded number
Dim dblFactor As Double
Dim dblTemp As Double
dblFactor = 10 ^ intDecimals
dblTemp = dblNumber * dblFactor + 0.5
dhRound = Int(dblTemp) / dblFactor
End Function
Hope that helps.
-- Andy
Note that this function assumes the caller has checked the input argument to ensure it is a valid
numeric value.
[The function provided by Andy Baron does not work correctly for negative amounts (due to the use of
Int rather than Fix, and not adjusting the sign on the one-half offset).]
Function round_to_pennies(ByVal in_dollars As Variant) As Currency
On Error GoTo rtp_err
Dim pennies As Double
pennies = CDbl(in_dollars * 100#)
round_to_pennies = CCur(Fix(pennies + (Sgn(pennies) * 0.5))) / 100@
Exit Function
rtp_err:
round_to_pennies = 0@
MsgBox Error$, 16, "round_to_pennies"
Exit Function
End Function
Alden
Mike Painter wrote in message <6g5uv4$4fh$1...@newsfep3.sprintmail.com>...
Option Compare Database
Option Explicit
Const Factor = 100
'=====================================================
' RoundAU and TruncAU are designed to be added to the
' AfterUpdate property on a form control.
'=====================================================
Function RoundAU(X As Control)
X = Int(X * Factor + 0.5) / Factor
End Function
Function TruncAU(X As Control)
X = Int(X * Factor) / Factor
End Function
'=====================================================
' RoundCC and TruncCC are designed to be used in
' expressions and calculated controls on forms and reports.
'=====================================================
Function RoundCC(X)
RoundCC = Int(X * Factor + 0.5) / Factor
End Function
Function TruncCC(X)
TruncCC = Int(X * Factor) / Factor
End Function
I've used the RoundCC(X) function on the calculated value and it uses only
two decimal places in the value and the calculation.
Thanks again.......
Allan Bach
ab...@ptd.net
Function dhRound(dblNumber As Double, intDecimals _
As Integer) As Double
' Rounds a number to a specified number of decimal
' places. 0.5 is rounded up
' From "VBA Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 1997; Sybex, Inc. All rights reserved.
' In:
' dblNumber:
' The number to be rounded
' intDecimals:
' The number of decimal places to round to
' Out:
' Return Value:
' The rounded number
Dim dblFactor As Double
Dim dblTemp As Double
Dim intSign As Integer
intSign = Sgn(dblNumber)
dblFactor = 10 ^ intDecimals
dblTemp = Abs(dblNumber) * dblFactor + 0.5
dhRound = intSign * Int(dblTemp & "") / dblFactor
End Function
Assuming one decimal place only is required, do you mean that 0.58 becomes
0.6, while 0.59 becomes 0.5?
-- Andy
0.575 becomes 0.58, 0.585 becomes 0.58, 0.595 becomes 0.60, 0.605 becomes
0.60, etc.
Alden
Paul Thornett wrote in message
<#lAmhvPY...@uppssnewspub04.moswest.msn.net>...