round() Returns Incorrect Results: Looking for Reliable Rounding Method

Certified Associate Developer

Hi everyone,

I’m currently experiencing an issue where the round() function does not return the expected results.
Below are some examples. In case 2, the expected result is 512.93, but Appian returns 512.92.
Additionally, in case 3, even when applying the workaround recommended in KB-1426, the output is still not correct.

KB1426 document : community.appian.com/.../kb-1426-unexpected-results-on-decimal-calculations-and-rounding

If the round() function cannot reliably produce correct rounding results in cases like these,
is there any known alternative approach — such as a custom Expression Rule or reusable utility — to achieve accurate decimal rounding in Appian?

I’m looking for:

  • A method that consistently returns mathematically correct rounding results

  • A reusable rule that avoids floating-point precision issues

  • Any best practices other users may have implemented for similar cases

Any suggestions, patterns, or examples would be greatly appreciated.

Thank you.

Hatsune

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    This is expected behavior in Appian. The round() function is accurate, but Appian stores decimal numbers using IEEE-754 floating-point, which cannot represent many decimal values exactly. Because of this, values like 10.22 may internally be stored as 10.21999999999999, and round() then appears to give an incorrect result.

    you can use 

    roundup(local!value, 2)
    rounddown(local!value, 2)

    For consistent results, especially in financial or UI use, wrap your rounding with fixed() to ensure exact decimal formatting.

  • +1
    Certified Lead Developer

    This is know issue with Floating-point representation limitation, This affects all programming languages (Java, JavaScript, Python, etc.), not just Appian.

    Create reusable rule like this and test you cases.

    if(
      /* Check if the digit after decimal place is 5 */
      mod(
        floor(ri!value * power(10, ri!decimals + 1)),
        10
      ) = 5,
      /* If it's 5, use roundup */
      roundup(ri!value, ri!decimals),
      /* Otherwise use normal round */
      round(ri!value, ri!decimals)
    )


  • 0
    Certified Lead Developer

    In addition to the prior answers, it will do you a lot of good to learn more about how Appian differentiates between *stored values* and *displayed values* - often (even in the output of an Expresison Rule) Appian will do its own transformation/rounding/generalization on the value displayed to you (as if it were being displayed to a general end user), causing there to be some situations where you see a value you perceive to be incorrect, even while the actual value Appian is holding is the correct one.  This can often be mitigated by, for example, forcing Appian to resolve to a certain decimal place by using functions like "text()", "fixed()", etc.

  • 0
    Certified Associate Developer

    Thank you all for your replies. 

    I'll create expression rule as an alternative of round() function.