I'm using the internal round() function in A2003, but it is not working. My number I am rounding to 2 decimal places is 10.325. This should round to 10.33, but Access is rounding it to 10.32.
I also found an external function on the internet which has the same error. Here is the function:
How can I get Access to round properly? This is a very serious problem to be a penny off. When you are talking about a million calculations, those million pennies really add up.
EDIT:
The Number that is passed to this function is actually of type Single. Here is my broken down code so I could trace what is going on:
I also found an external function on the internet which has the same error. Here is the function:
Code:
Function RoundIt(ByVal Number As Variant, ByVal Decimals As Integer) As Variant
If Decimals >= 0 Then
RoundIt = Int(Number * 10 ^ Decimals + 0.5) / 10 ^ Decimals
Else
MsgBox "Invalid decimal places."
RoundIt = Number
End If
End Function
EDIT:
The Number that is passed to this function is actually of type Single. Here is my broken down code so I could trace what is going on:
Code:
Public Function Roundcr(ByVal Number As Variant, ByVal Decimals As Integer) As Variant
Dim v As Variant
' At this point, Number=10.324999999999 but displays as 10.325. Thus begins my problem.
If Decimals >= 0 Then
v = (Number * (10 ^ Decimals)) ' v=1032.4999999
v = v + 0.5 ' v=1032.9999999
v = Int(v) ' v=1032
v = v / (10 ^ Decimals) ' v=10.32 which is NOT CORRECT.
Roundcr = v
Else
MsgBox "Global::Roundcr: Invalid decimal places."
Roundcr = Number
End If
End Function
Last edited: