Results 1 to 5 of 5
  1. #1
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    how to get decimal value from numeric value

    I want that whenever a three digit numeric number is entered in the text box made in the form it should be converted to decimal from the after update event.


    for example---

    input 453 output display .453
    input 678 output display .678
    input 100 output display .100
    input 020 output display .020

    what could be the code for this?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try the following in the AfterUpdate event:
    Code:
        If Me.ActiveControl >= 100 And Me.ActiveControl <= 999 Then        
           Me.ActiveControl = "." & Me.ActiveControl
        End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    it should be converted to decimal
    decimals will always have a value before the decimal point, even if it is 0. To display what you want (no characters before the decimal point) it will need to be displayed as a string as shown by Bob.

    If you need to keep it as a number, in the after update event of your textbox put

    txtEntry=txtEntry/1000

    and in the format property for the txtEntry control put

    .000

    Note that the number has been converted from 123 to 0.123 and the format property hides the zero

    Another way is to use an input mask - just set it to .###, no code required. and the underlying value will remain as 123

    Which method works for you depends on what you are going to do with the value

  4. #4
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    thanks for replay...

  5. #5
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    thanks CJ_London

    this code ---

    Private Sub TXT8_AfterUpdate()

    Me.TXT8 = Me.TXT8 / 1000
    End Sub

    is best for me..... thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 04-17-2020, 08:42 PM
  2. how to trim a numeric value?
    By eeps24 in forum Access
    Replies: 7
    Last Post: 08-28-2015, 10:25 AM
  3. Convert decimal comma to decimal point
    By Hans Karlsson in forum Programming
    Replies: 3
    Last Post: 06-30-2014, 01:56 PM
  4. Numeric overflow
    By slimjen in forum Forms
    Replies: 10
    Last Post: 10-19-2011, 01:26 PM
  5. Filtering for numeric value
    By Bear in forum Access
    Replies: 21
    Last Post: 07-31-2011, 05:08 PM

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