Skip to main content
November 7, 2023
Question

How to store and show 7 digit after decimal using number(decimal) data type

  • November 7, 2023
  • 9 replies
  • 0 views

Hi All,

I need to show and store 7 digits after decimal and before decimal its 'n' number and the data type is number(decimal) how I can do that? 

Thanks in advance.

    9 replies

    stefanhelzle0001
    Brainy
    November 7, 2023
    stewart.burchell
    November 7, 2023

    Do you want to allow the user to enter any number but always have it be presented in the User Interface always with the full 7 digits after the decimal point? Examples:

    Enter: 123  -> presented as 123.0000000

    Enter: 12.12345678 -> presented as 12.1234568

    Enter: .2 -> presented as 0.2000000

    Is that the requirement?

    November 8, 2023

    Thanx For the reply Stewart 

    If user enter 12345.1234567899 then in UI it should show and store only 1234.1234567

    if enter 123456.12 it will show as it is, only after 7 digits it will not show 

    stewart.burchell
    November 8, 2023

    Ok, so you need to separate in your mind how the data is held in memory (this will be using a Decimal data type) from how you want it captured/presented to the user. This code snippet might help:

    a!textField(
        label: "My Decimal",
        value: fixed(ri!myDecimal,7),
        saveInto: {
          a!save(
            ri!myDecimal,
            if(
              fn!regexmatch(
                "^\d*(\.\d+)?$",
                save!value,
                "i"
              ),
              save!value,
              0
            )
          ),
        }
      ),

    The ri!myDecimal is of type Number(Decimal) but as you can see I'm using a Text Field to allow the user to enter their value. 

    Where the text entered conforms to the pattern of a Decimal (that's what the RegEx expression is checking) then it is presented as a Decimal with 7 digits after the decimal point (that's what the fixed() function is doing)

    Because the input field is text you need to handle the fact that a user might enter non-decimal representations e.g. "ABC". That's what the second part of the if() statement is doing.

    Hope this helps.

    November 7, 2023

    text(ri!decimal,"0.0000000")

    You can use this code to show a decimal number as text with the required format

    November 8, 2023

    Thanx for the reply 

    but it will return text right, I want number decimal to be return will it possible?

    November 8, 2023

    todecimal(text(ri!decimal, "0.0000000"))

    i think it will work for your requirement

    please check