Results 1 to 6 of 6
  1. #1
    cuongmyh is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2015
    Posts
    3

    Help me! Different decimal places for text box in different row!

    Hi!
    I have continuos form! in this form, i have field "Amount". I want to format this texbox with different decimal place in different row.
    ex:
    R/M Amount


    -----------------
    A 10.23
    B 9.245
    C 12.5623

    How do i do?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can use a calculated field like this:
    Code:
    AmountToShow: IIf([R/M]="A",Round([Amount],2),IIf([R/M]="B",Round([Amount],3),IIf([R/M]="C",Round([Amount],4),[Amount])))

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Be aware that Round() function uses even/odd rule, in case that matters to you.

    Round(10.225,2) = 10.22

    Round(10.226,2) = 10.23

    Round(10.235,2) = 10.24
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You could also use the Format function, but just bear in mind that returns a Text value (not a numeric one).

    Code:
    FORMAT([Amount],"0.00")

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603

    Custom Round Function

    Which is why I built a custom function,
    Code:
    Function RRound(FieldValue As Variant, Optional intPos As Integer = 0) As Variant
    '--------------------------------------------------
    ' Function RRound() rounds value to designated decimal position.
    ' If argument does not contain data, RRound returns null.
    ' Use because intrinsic Round uses even/odd (banker's) rounding.
    ' Also, Format and FormatNumber functions don't use even/odd but
    ' generate a string result which is often inconvenient.
    '--------------------------------------------------
    Dim strZeros As String
    Dim i As Integer
    If intPos = 0 Then
        strZeros = 0
    Else
        For i = 1 To intPos
            strZeros = strZeros & 0
        Next
        strZeros = "0." & strZeros
    End If
    RRound = IIf(Not IsNull(FieldValue), Val(Format(FieldValue, strZeros)), Null)
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Which is why I built a custom function,
    Nice! Gotta love those UDFs!

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

Similar Threads

  1. Converting text to 2 decimal places
    By lwilt in forum Access
    Replies: 1
    Last Post: 09-13-2013, 09:58 AM
  2. Decimal Places
    By momodoujimnjie in forum Access
    Replies: 1
    Last Post: 01-09-2013, 04:49 AM
  3. Report decimal places
    By jackyoung2012 in forum Reports
    Replies: 1
    Last Post: 03-22-2012, 12:12 PM
  4. Limiting decimal places
    By Cran29 in forum Access
    Replies: 13
    Last Post: 01-08-2011, 08:01 AM
  5. Changing decimal places
    By stupesek in forum Reports
    Replies: 12
    Last Post: 09-01-2010, 11:33 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