Results 1 to 7 of 7
  1. #1
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659

    Question Problems with Currency Datatype

    I don't wish to round my values, I want to just truncate the end of my data.

    Public Function t1() As Currency


    Dim A1 As Currency
    Dim A2 As Single

    A1 = 2.01
    A2 = 2.0072121

    t1 = A1 * A2

    End Function

    in the intermediate
    ?t1

    t1 show 4 decimal places, If i use formatnumber/formatcurrency with the 2 decimal place argument then the value gets rounded. I am not looking to round.

    Should I evaluate the number like a string and use a Mid function to make the data only return 2 decimals without rounding?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can use the INT function to drop the decimal places (it just return the INTEGER portion of your number).

  3. #3
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Dropping the decimals is not an option i need to keep track of the last 2 places. Currently I am thinking about using something along the lines of

    Public Function t1() As Currency
    Dim A1 As Currency
    Dim A2 As Single
    Dim intPos As Integer
    A1 = 2.245554
    A2 = 2.2525
    t1 = A1 * A2
    intPos = InStr(t1, ".")
    t1 = Left(t1, intPos + 2)
    End Function

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Should I evaluate the number like a string and use a Mid function to make the data only return 2 decimals without rounding?
    Yes, I think so.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Thank you Bob I will try this out next week.

    marking as solved =)

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sorry. I misread your original question.
    You could multiply by 100, take the INT, and divide by 100, i.e.
    Code:
    Public Function t1() As Currency
    
        Dim A1 As Currency
        Dim A2 As Single
        Dim intPos As Integer
    
        A1 = 2.245554
        A2 = 2.2525
        t1 = INT(A1*A2*100)/100
    
    End Function
    Acutally, you wouldn't even need a UDF to do this. Just use the expression in the following format:
    Code:
    Expr1: INT(A1*A2*100)/100

  7. #7
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    That makes a bit more sense, thanks Joe.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 12-12-2013, 02:38 AM
  2. DLookUp DataType Mismatch Error
    By theosgood in forum Programming
    Replies: 2
    Last Post: 10-29-2013, 10:04 AM
  3. Replies: 8
    Last Post: 05-11-2012, 04:41 PM
  4. Binary datatype
    By huBelial in forum Access
    Replies: 1
    Last Post: 04-04-2011, 02:02 PM
  5. Replies: 2
    Last Post: 03-23-2011, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums