Rounding Error in Access 2013

Kathleen Combs 1 Reputation point
2022-04-05T17:06:25.973+00:00

Can you tell me why Access 2013 would round 410.50 down to 410 instead of rounding up to 411? In this example all of the other values in .5 round up. 190237-image.png

Thanks.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
888 questions
{count} votes

8 answers

Sort by: Most helpful
  1. Kathleen Combs 1 Reputation point
    2022-04-05T18:56:09.313+00:00

    In Access Query

    Round([Hours],0)

    0 comments No comments

  2. Viorel 118.4K Reputation points
    2022-04-05T19:37:24.283+00:00

    Try an alternative: Int([Hours]+0.5).

    Round seems to performs "Banker's rounding".

    0 comments No comments

  3. Kathleen Combs 1 Reputation point
    2022-04-05T19:56:05.817+00:00

    Thanks. Will that affect the other data where the rounding is correct? I'm curious if that formula you are suggesting will round up on all of all rows rather than the ones that have .5 or greater?

    Kind of seems like this is a bug in the Access software? I don't understand why it rounds correctly for others that end in .5? Only seems to be a problem with one of them?


  4. Kathleen Combs 1 Reputation point
    2022-04-05T22:13:11.057+00:00

    It was my understanding that an amount that ended in .5 or above would be rounded up. Below .5 is rounded down. That has been my experience with other software packages. Could you please tell me how to view detailed examples of banker's rounding and why that was chosen.

    I do appreciate your answer. I'm moving on since I don't see a good answer for this. So I'm just curious at this point.


  5. Gustav 712 Reputation points MVP
    2022-04-06T10:07:57.82+00:00

    Round doesn't "seem" to perform Banker's Rounding - rounding to nearest even - it does perform Banker's Rounding, as do all the conversion functions that will round: CByte, CInt, CLng, CCur. The only function that performs true 4/5 rounding as you learned in school, is Format.

    Further, Round is quite buggy, thus should only be used for coarse rounding, for example plotting a graph.

    For any serious or extreme rounding, refer to my rounding methods found at GitHub: VBA.Round

    The function, you probably need, is:

    ' Rounds Value by 4/5 with count of decimals as specified with parameter NumDigitsAfterDecimal.
    '
    ' Rounds to integer if NumDigitsAfterDecimal is zero.
    '
    ' Rounds correctly Value until max/min value limited by a Scaling of 10
    ' raised to the power of (the number of decimals).
    '
    ' Uses CDec() to prevent bit errors of reals.
    '
    ' Execution time is about 1µs.
    '
    ' 2018-02-09. Gustav Brock, Cactus Data ApS, CPH.
    '
    Public Function RoundMid( _
        ByVal Value As Variant, _
        Optional ByVal NumDigitsAfterDecimal As Long, _
        Optional ByVal MidwayRoundingToEven As Boolean) _
        As Variant
    
        Dim Scaling     As Variant
        Dim Half        As Variant
        Dim ScaledValue As Variant
        Dim ReturnValue As Variant
    
        ' Only round if Value is numeric and ReturnValue can be different from zero.
        If Not IsNumeric(Value) Then
            ' Nothing to do.
            ReturnValue = Null
        ElseIf Value = 0 Then
            ' Nothing to round.
            ' Return Value as is.
            ReturnValue = Value
        Else
            Scaling = CDec(Base10 ^ NumDigitsAfterDecimal)
    
            If Scaling = 0 Then
                ' A very large value for NumDigitsAfterDecimal has minimized scaling.
                ' Return Value as is.
                ReturnValue = Value
            ElseIf MidwayRoundingToEven Then
                ' Banker's rounding.
                If Scaling = 1 Then
                    ReturnValue = Round(Value)
                Else
                    ' First try with conversion to Decimal to avoid bit errors for some reals like 32.675.
                    ' Very large values for NumDigitsAfterDecimal can cause an out-of-range error when dividing.
                    On Error Resume Next
                    ScaledValue = Round(CDec(Value) * Scaling)
                    ReturnValue = ScaledValue / Scaling
                    If Err.Number <> 0 Then
                        ' Decimal overflow.
                        ' Round Value without conversion to Decimal.
                        ReturnValue = Round(Value * Scaling) / Scaling
                    End If
                End If
            Else
                ' Standard 4/5 rounding.
                ' Very large values for NumDigitsAfterDecimal can cause an out-of-range error when dividing.
                On Error Resume Next
                Half = CDec(0.5)
                If Value > 0 Then
                    ScaledValue = Int(CDec(Value) * Scaling + Half)
                Else
                    ScaledValue = -Int(-CDec(Value) * Scaling + Half)
                End If
                ReturnValue = ScaledValue / Scaling
                If Err.Number <> 0 Then
                    ' Decimal overflow.
                    ' Round Value without conversion to Decimal.
                    Half = CDbl(0.5)
                    If Value > 0 Then
                        ScaledValue = Int(Value * Scaling + Half)
                    Else
                        ScaledValue = -Int(-Value * Scaling + Half)
                    End If
                    ReturnValue = ScaledValue / Scaling
                End If
            End If
            If Err.Number <> 0 Then
                ' Rounding failed because values are near one of the boundaries of type Double.
                ' Return value as is.
                ReturnValue = Value
            End If
        End If
    
        RoundMid = ReturnValue
    
    End Function
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.