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

Certified Associate Developer

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.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 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.