I'm working on a custom currency input field component and facing a challenging issue with decimal value conversion and rounding when values exceed 10,000 (5+ digits).
Here's my current implementation:
a!localVariables( a!textField( label: ri!label, labelPosition: a!defaultValue(ri!labelPosition, "ABOVE"), value: a!currency( isoCode: a!defaultValue(ri!isoCode, "BRL"), value: rule!process_BRLInputSanitizer( value: ri!value, toDecimal: true, showSeparators: false ), decimalPlaces: 2, showSeparators: true ), placeholder: ri!placeholder, saveInto: a!localVariables( { a!save( ri!value, a!currency( isoCode: a!defaultValue(ri!isoCode, "BRL"), value: rule!process_BRLInputSanitizer( value: save!value, toDecimal: true, showSeparators: false ), decimalPlaces: 2, showSeparators: true ), ), ri!saveInto } ), disabled: a!defaultValue(ri!disabled, false), readOnly: a!defaultValue(ri!readOnly, false), refreshAfter: "KEYPRESS", validations: { ri!validations }, showWhen: a!defaultValue(ri!showWhen, true), instructions: ri!instructions, helpTooltip: ri!helpTooltip ) )
Supporting Rule (process_BRLInputSanitizer):
a!localVariables( local!toDecimal: a!defaultValue(ri!toDecimal, false), local!value: tostring(ri!value), local!left: substitute(local!value, ",", "."), local!right: substitute(local!value, ".", ","), local!result: if( local!toDecimal, concat( left(local!right, len(local!right) - 3), right(local!left, 3) ), concat( left(local!left, len(local!left) - 3), right(local!right, 3) ) ), if( a!defaultValue(ri!showSeparators, true), local!result, if( local!toDecimal, substitute(local!result, ",", ""), substitute(local!result, ".", "") ) ) )
Questions:
I'm essentially trying to create a currency input that displays proper formatting (R$323,845.27) while maintaining the underlying decimal value for record Type integration.
Any recommendations for existing solutions or insights into the rounding behavior would be greatly appreciated!
Thank you all for your time and assistance.
Discussion posts and replies are publicly visible
Appian's default way of displaying decimal numbers takes some sometimes unintuitive liberties with the number of significant figures shown - in ways that are a little unintuitive and opaque to not only the end user but also the designer (frustratingly). I'm not exactly sure I'm comprehending the manual conversions you're with your utuility rule, but I was under the impression that a!currency() was supposed to handle things like "dots instead of commas and commas instead of dots" automatically for currencies that use opposing systems (though i haven't tested this). BTW, are users not using locales that support the proper number entry system inherently? I thought it worked without manual conversion when the locale was set right (also haven't personally tested though).
My general advice at this point would be to go back to basics and make sure you're doing any manual conversion on a displayed number (versus the underlying decimal value) only at the very end, to avoid it becoming confused.