sadams1970
New Member
- Joined
- Aug 28, 2003
- Messages
- 16
is they anyway to round numbers in Access? I'm a relatively advanced Access user, but can't figure this one out.
Function Ceiling(N, ByVal Precision)
'
' Similar to Excel's Ceiling function
' Rounds up to the next higher level of precision.
' Precision cannot be 0.
'
Dim Temp As Double
Precision = Abs(Precision)
Temp = Int(N / Precision) * Precision
If Temp = N Then
Ceiling = N
Else
Ceiling = Temp + Precision * Sgn(Temp)
End If
End Function
Function Floor(N, ByVal Precision)
'
' Similar to Excel's Floor function
' Rounds down (toward zero) to the next higher level of precision.
' Precision cannot be 0.
'
Precision = Abs(Precision)
Floor = Int(N / Precision) * Precision
End Function
Function Round2(X)
'
' Rounds a number to 2 decimal places
' Uses arithmatic rounding
'
Round2 = Int(X * 100 + 0.5) / 100
End Function
Function Round2C(X)
'
' Rounds number to 2 decimal places
' Uses arithmatic rounding
' Designed for use with Currency values
'
If IsNull(X) Then
Round2C = Null
Else
Round2C = CCur(Int(X * 100 + 0.5) / 100)
End If
End Function
Function Round2CB(X As Variant) As Variant
'
' Banker's rounding of Currency to 2 decimal places.
'
Dim Temp As Currency, ITemp As Currency, Digit As Integer
If IsNull(X) Then Exit Function
Round2CB = CCur(X / 100) * 100
End Function
Function RoundN(X, N As Integer)
'
' Rounds a number to N decimal places
' Uses arithmatic rounding
' N should be in the range 0-10 for proper results
'
Dim Factor As Long
Factor = 10 ^ N
RoundN = Int(X * Factor + 0.5) / Factor
End Function