FreeMarker is a java based template engine for complex template processing.
This requires the library freemarker-2.3.16.jar to be in classpath.
The following example shows various number format settings in FreeMarker.
//Get template from classpath
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(NumberSettingsTest.class, "/");
Template template = cfg.getTemplate("numbers.ftl");
//Prepare data model
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("num", new Long("123456789"));
//Merge template and data
OutputStreamWriter output = new OutputStreamWriter(System.out);
template.process(dataModel, output);
}
}
It gives the following output,
Num with default format : 123,456,789
Num with 0.## format : 123456789
Num with ,##0.00 format : 123,456,789.00
$ {num?string.number} : 123,456,789
$ {num?string.currency} : $123,456,789.00
$ {num?string.percent} : 12,345,678,900%