Results 1 to 5 of 5

Thread: rounding

  1. #1
    Join Date
    Jun 2002
    Posts
    173

    Unanswered: rounding

    Does anyone know a function I can use in Access97 to round a field to 2 decimal places (ie. for a currency value).

  2. #2
    Join Date
    Jun 2002
    Posts
    173
    forgot to mention that the "round" function does not work in Access97, only Access 2000 and above.

  3. #3
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    Just add that function in a module, it is not the perfect round function, but you can modify it easily
    Code:
    'Beware, only round for TWO decimal (easy to add for more) and
    'may not work on BIG double  (since using multiplication)
    Public Function round(dblToRound As Double) As Double
    
        Dim dblWorkNumber As Double
        Dim dblResult As Double
    
        dblWorkNumber = dblToRound * 100
        
        If dblWorkNumber - Int(dblWorkNumber) > 0.5 Then
            dblResult = (Int(dblWorkNumber) + 1) / 100
        Else
            dblResult = Int(dblWorkNumber) / 100
        End If
        
        round = dblResult
        
    End Function
    JefB - hope it helps

  4. #4
    Join Date
    Jun 2002
    Posts
    173
    Thanks it works great. How would I do this in a query as well?

  5. #5
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    Function DnRound(Number As Double, decimals As Integer) As Double
    DnRound = Int(Number * 10 ^ decimals + 0.5) / 10 ^ decimals
    End Function

    It rounds to any number of decimal. If 'decimal' is negative, it will round to nearest 10, 100 or whatever.

    Use it in a query just like using any other function.

    Regards,

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •