Hi,
Whenever I'm trying to enter 271.64 or 2**.65 where (** can be any number) it's getting converted to 2**.64
I'm using below expression for this:
a!floatingPointField( label: "Test Decimal Value", value: todecimal(fixed(trunc(ri!value, 2))), saveInto: ri!value)
Not sure, if this is an issue from Appian. Can anyone confirm this.
Thanks in advance.
Discussion posts and replies are publicly visible
is it necessary to truncate upto 2 decimals?once try with 3 decimals.
There is nothing "converted". This is just the way how the values is displayed in both places.
Hi, Please try to use this code which will give you 299.65
a!floatingPointField( label: "Test Decimal Value", value: todecimal(fixed(trunc(299.65, 3))), )
It's working with three decimal values, but business requirement is to keep up to two decimal values. And this is happening only in this scenario not with any other numbers. Like:
Hi Stefan, Thanks for your reply. But, issue is it's only happening with this specific number 2**.65 which is converting into 2**.64.
Hi Harshitha,
Thanks for the solution, but here we are passing both parameters of trunc function as rule inputs:
There is a general problem with how computers store decimal values. Check this:
https://www.baeldung.com/cs/floating-point-numbers-inaccuracy
You will see this with a lot of numbers. Depending in the internal representation it works most of the time and sometimes not. And there is no real fool proof way of managing this. Mathematical rounding should get you covered most of the time. This conversion to a string and back to a decimal will probably not.
have you tried with trim()?
Can you please try this code which will solve your issue
a!floatingPointField( label: "Test Decimal Value", value: todecimal(fixed(299.65,2)) )
Fascinating bug you found there.
From my testing, the issue seems to be with the trunc() function, fixed() does not exhibit the same behavior.
I recommend reducing your expression to: fixed(ri!value, 2)
It is not necessary to use todecimal(), as the a!floatingPointField() performs the cast as well.
So, right now, you are truncating as a floating point number, converting to a string, and setting a fixed number of characters, then converting BACK to a floating point number, for a field than then casts to a floating point number automatically. A few more steps than necessary, I should think.
Take care,
JM