Expect formatFloat to adhere to locale

2
Hi, When float $Attribute has value 12.345,67 I expect to see 12.345,67 in a text field when the locale is nl_NL and 12,345.67 when it is en_US. This works as expected. When I use a microflow label and its corresponding microflow says formatFloat($Attribute , '#,###.#') I get 12,345.67 in all cases. The default for this project is en_US. When I use the nl_NL notation the application has runtime errors because it expects the en_US notation. According to the documentation (https://world.mendix.com/display/refguide3/Parse+and+format+float+function+calls) I expect it to adhere to the locale. See the reference http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html at the top of the page. So, what it the right behavior to expect, and in case the above is as designed, what can I do to get what I want. Adding an exclusive split on the user's locale to each microflow that uses formatfloat is not a good option. I haven't used formatdate/time in a microflowlabel but if that one behaves the same... Regards, Paul
asked
1 answers
3

Hi Paul,

Apologies you did not get an answer for a while, a lot of people had a Christmas break I guess :-). I would also expect formatFloat and parseFloat to take the locale in account, but in our implementation it seems only the default locale is used at the moment. This is a bug, could you report this in the support portal ?

As a workaround you could create a Java action which uses the following code:

new DecimalFormat("#,###.#", new DecimalFormatSymbols(Core.getLocale(context))).format(number);

The DecimalFormatSymbols based on your context locale will make sure it will be formatted in the right way.

answered