formatDecimal($Order/Discount,#.###,##) gives Malformed pattern #.###,##

2
I need to convert a Decimal into a string, but formatDecimal($Order/Discount,'#.###,##') give the following error: Caused by: com.mendix.languages.expressions.ExpressionException: java.lang.IllegalArgumentException: Malformed pattern "#.###,##" my language is English United States ( Default )
asked
4 answers
4

The decimalFormat currently does work as expected in the latest 6 and 7 releases. When working with the format it is important to make the distinction between the notation you use in your microflow (code) and what is being show to the user.    

The decimal format microflow expression uses the java library DecimalFormat, (this is the javadoc)    
When writing expression it is important to be aware of what you are writing, just like in any other programming language a decimal separator is always represented by the . and a thousand separator is also always a ,    

That fact that you are a Dutch guy programming for a Dutch audience doesn't change your compiler. This same applies to microflow expressions, whenever you are expressing a number you must use a dot as your decimal separator even if your project is 100% Dutch.    

 

To get back to your expression, the formatDecimal expression always expects a , as thousand separator and a . as decimal separator. This expression only allows you to group digits before the decimal mark, you can't group decimals (that is why you get this error).  The conclusions you wrote in your earlier post are accurate.

formatDecimal($Test\DecimalValue,'#,###.##') does give 1,800 as an output.  But this is based on your language. If you have a project that has language en_US Mendix and Java will format the number according to this localization.    

Using the same pattern '#,###.##', but with the nl_NL localization associated to the user that runs the microflow will generate an ouput: 1.800  (note the . )    

 

The expression will always format according to your language. And you can use the pattern to highlight what is showing. Some examples with nr: 1800

#,###.##    for nl_NL:   1.800  for en_US:  1,800

###0.0#    for nl_NL:   1800,0  for en_US:  1800.0

###.0#    for nl_NL:   800,0  for en_US:  800.0   (make sure your pattern has sufficient characters to represent your nr)

#,#,##.0#    for nl_NL:   1.8.00,0  for en_US:  1,8,00.0

answered
5

Mike, Ronald, thx for your help I did some test:

App with English US as default language:
DecimalValue = 1800

formatDecimal($Test\DecimalValue,'#,###.##') gives 1,800
formatDecimal($Test\DecimalValue,'#.###,##') gives the error Malformed pattern "#.###,##"

DecimalValue = 1800.65
formatDecimal($Test\DecimalValue,'#,###.##') gives 1,800.65
formatDecimal($Test\DecimalValue,'#.###,##') gives the error Malformed pattern "#.###,##"

App with Dutch as default language:
DecimalValue = 1800
formatDecimal($Test\DecimalValue,'#,###.##') gives 1,800
formatDecimal($Test\DecimalValue,'#.###,##') gives the error Malformed pattern "#.###,##"

DecimalValue = 1800.65
formatDecimal($Test\DecimalValue,'#,###.##') gives 1,800.65
formatDecimal($Test\DecimalValue,'#.###,##') gives the error Malformed pattern "#.###,##"

So English or Dutch need the pattern #,###.##

formatDecimal(1800,'#,###.00') gives 1,800.00
formatDecimal(1800.65,'#,###.00') gives 1,800.65

Conclusion
pattenrn need .00 to show always decimals and always #,###.00 for all languages.

Reason for a ticket to Mendix?, because search and replace , and . sounds like a ducktape solution

answered
0

If you are using US language then I think you should change the format into #,###.## since in the US the use of a . and a , is exact the opposite what we use in the Netherlands for instance.

Regards,

Ronald

 

answered
0

Jan -

Do you have formatDecimal working without errors anywhere in your app?  I use it extensively with many different formats with no issues.  I did a bit of research and it looks like the underlying Java format always uses the comma as a grouping separator and the dot as a decimal separator - see documentation here.  Based on your message, I think the correct pattern would be '#,###.##' .  Just curious, di you try a different format pattern like '###.##' or '###.00' to see if you get a different result?

Mike

answered