Decimal calculation

Hi All,

I am having one use case where I want to store decimal value.

But when I enter amount like 10.10 in decimal type field , it is returning 10.1 when I click outside because it is decimal type value.

I want same value as user entered. e.g If I entered 10.10, value should remain same 10.10 not 10.1.

 

Please leave your suggestion to achieve this.

 

Thanks,

Vinod Tate

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer
    not possible with a!floatingPointField component. convert it to text component and use fixed function on value as below

    fixed(if(rule!APN_isBlank(local!dec),0,local!dec),2,1)
  • Hi ,

    It's Appian behavior to trim leading and preceding 0's from the value of Decimal field. If you want to the value to be stored as is, then you can use Text Field. Even in that case, the variable you are saving to will have to of type Text only, Decimal type will again trim 0's.

    Also, you might have to handle all the validations explicitly in the text field like Alphabetical and Special characters should not be allowed.

    Thanks,
    Thasneem.
  • Hi Vinod,
    As suggested by Thasneem, if you want to retain the decimal value as it is, Use text field with proper validations to restrict user from entering Alphabetical and Special characters. This should work fine if you want to use the value only for display purpose.

    Where as this approach will not suggestible if you want to do any comparisons or calculations with that decimal value(for calculations again you need to convert it to to decimal, same issue will occurs)

    Thanks,
    Sindhu
  • Thanks for response.

    I am using textfield only but cdt data type is decimal where am string value.

    I have changed data type to string to achieve this and it is working fine.

    Actually changing data type was creating lot of work like validation, change CDT, Dependent objects hence I was looking for some alternate solution.
  • I know that it's an old discussion but the answer here was not as good as I expected.

    I have one CDT that retains currency values like you said: 270,000.83 and sometimes it's 270.000,83 or even 270000,83.

    Appian acknowledges decimal as \d.\d{2} (270000.83 can be converted as decimal, for example).

    So in our case, we needed to convert the possible values to real decimals and to be possible sum these values, for example.

    When we managed to convert the Text do decimal, we noticed that the decimal was truncated at the end.

    The text 270.000,83 was convert to 270000.8 --' and if we convert it back to Text, it remains truncated.

    To manage that, in our case, what worked is create an Expression Rule to convert to decimal, make any sum or mathematical expressions and, finally, convert to currency (https://docs.appian.com/suite/help/22.4/fnc_text_currency.html). Doing that, the two digits after ',' are back! \o/

    Here are my ER to transform Text to Decimal (String_To_Decimal), if anyone finds it usefull (rule input: valorStr):

    a!localVariables(
    local!valorTeste: ri!valorStr,
    local!testRegex1: fn!regexmatch("\,\d{2}(?!\d)", local!valorTeste),
    local!resRegex1: if(
    local!testRegex1,
    with(
    local!matchMarker: regexinsertmatchmarkers(
    pattern: "\,\d{2}(?!\d)",
    searchString: local!valorTeste,
    leftMarker: "a",
    rightMarker: null,
    FirstMatchOnly: true
    ),
    fn!regexreplaceall(
    pattern: "a\,",
    searchString: local!matchMarker,
    replacementString: "."
    )
    ),
    local!valorTeste
    ),
    local!testRegex2: fn!regexmatch("\.\d{3}(?!\d)", local!resRegex1),
    local!resRegex2: if(
    local!testRegex2,
    with(
    local!matchMarker: regexinsertmatchmarkers(
    pattern: "\.\d{3}(?!\d)",
    searchString: local!resRegex1,
    leftMarker: "a",
    rightMarker: null,
    FirstMatchOnly: false
    ),
    fn!regexreplaceall(
    pattern: "a\.",
    searchString: local!matchMarker,
    replacementString: null
    )
    ),
    local!resRegex1
    ),
    local!testRegex3: fn!regexmatch("\,\d{3}(?!\d)", local!resRegex2),
    local!resRegex3: if(
    local!testRegex3,
    with(
    local!matchMarker: regexinsertmatchmarkers(
    pattern: "\,\d{3}(?!\d)",
    searchString: local!resRegex2,
    leftMarker: "a",
    rightMarker: null,
    FirstMatchOnly: false
    ),
    fn!regexreplaceall(
    pattern: "a\,",
    searchString: local!matchMarker,
    replacementString: null
    )
    ),
    local!resRegex2
    ),
    local!decimal: todecimal(local!resRegex3),
    /*currency(local!decimal)*/
    local!decimal
    )