Hello, folks

In our project we are using freemarker to process dynamic(written by users)
templates.
So, our code related to template processing looks like the following:

Configuration configuration = new Configuration();
configuration.setLocale(locale);
new Template("name", template, configuration).process(data, stringWriter);

Our requirements for processing output are
1. Number formatting should be localized
2. Fraction digits should never be cut. That means that 1.12345 should not
be displayed as 1.123. This happens because default value for
NumberFormat#maxFractionDigits is 3

We ended up by setting the following configuration option
conf.setNumberFormat("###,###.####################");

But I personally feel that working with format patterns is a bit
counter-intuitive and error-prone.
I would prefer the following:

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
numberFormat.setMaximumFractionDigits(Integer.MAX_VALUE);
configuration.setNumberFormat(numberFormat);

But setNumberFormat only accepts strings.
Looking at the source of freemarker.core.Environment it does not look like
a huge change to provide a method that would accept an instance of
NumberFormat.

Do you guys already have plans for implemenation of this change? I would
really appreciate having this functionality.




Thank you for your time,
Eduard

Reply via email to