Currency hard-coded formatting

USD has a format of #,##0.00 whereas KWD has a format of #,##0.000 and yes the third decimal is very critical and important given the currency’s high exchange value. I’m sure there are also currencies where the whole number after the decimal is not even wanted.

As below sample grep output shows, there is a lot of hard-coded formatting (250+) all over the place. Wouldn’t it make more sense to switch moqui behavior to parameterize currency formatting perhaps with some defaults. And if yes, which entity can hold this information best?

framework/src/main/groovy/org/moqui/impl/screen/ScreenForm.groovy:                    attrs = [format:"#,##0.00"]
framework/src/main/groovy/org/moqui/impl/screen/ScreenForm.groovy:                    attrs = [format:"#,##0.000"]

runtime/component/SimpleScreens/screen/SimpleScreens/Party/PaymentMethod/PaymentMethodFiles.xml:                <default-field><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Party/PaymentMethod/PaymentMethodFiles.xml:                <default-field><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                <default-field title="Actual Year"><display format="#,##0.00" text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                    <display format="#,##0.00" text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                <default-field title="Act P1"><display format="#,##0.0 " text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                    <display format="#,##0.00" text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                <default-field title="Act P2"><display format="#,##0.0 " text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                    <display format="#,##0.00" text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                <default-field title="Act P3"><display format="#,##0.0 " text-format="0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Budget/BudgetReport.xml:                    <display format="#,##0.00" text-format="0.00"/></default-field></field>

runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:            <field name="minAmount" align="right" show-total="min"><default-field title="Min"><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:            <field name="maxAmount" align="right" show-total="max"><default-field title="Max"><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:            <field name="avgAmount" align="right" show-total="avg"><default-field title="Avg"><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:                <default-field><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:            <field name="averageCost" align="right" show-total="avg"><default-field title="Avg Cost"><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:                <default-field><display format="#,##0.00"/></default-field></field>
runtime/component/SimpleScreens/screen/SimpleScreens/Accounting/Reports/SalesInvoiceAnalysis.xml:                <default-field title="Margin"><display format="#,##0.00"/></default-field></field>

Hi Taher,
yes, it would make sense from my point of view. We would welcome to see no decimal digits for CLP, and four decimal digits for CLF (not an official currency but really close to it, and widely used alongside CLP in Chile).

There is functionality in the L10Facade, which uses the amount of digits as defined by java.util.Currency.defaultFractionDigits().

So I figure the main part of the work is to determine which currency is the one to use. It can be specified in invoices and orders (in OrderHeader), while the mantle.ledger.config.PartyAcctgPreference entity defines the currency to use for one party’s accounting, and any user can set a preference for ‘CurrencyDefault’. So it really depends on the context which currency one should use.

Following on the comments from Jens, the main way already in the framework to do currency-aware number formatting is to use the display.@currency-unit-field attribute and leave the display.@format attribute unspecified.

Admittedly the use of format="#,##0.00" is a quick & dirty compromise that works for most cases and is easy/lazy. Many, or rather most, of these display elements should be updated to use the relevant currency for the context (from Invoice, OrderHeader, PartyAcctgPreferences, etc).

On a side note, the CurrencyDefault setting should never be used for display purposes, that should always come from data somewhere otherwise multi-currency gets broken. The default currency setting is only meant to be used for input purposes, including currency selection drop-downs, service in-parameters, etc.

1 Like