Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker, is it possible to set computer numbering format by default?

About FreeMarker, is it possible to instruct it to treat all numbers as "computer" ones by default?

I tried to apply

cfg.setSetting(Configurable.NUMBER_FORMAT_KEY, "computer");

or

cfg.setNumberFormat("computer");

to configuration object, but the outcome is not the desired. Believing this is the documentation's way to do it, is there anything wrong?

like image 578
Dimitrios Mistriotis Avatar asked Jan 30 '13 16:01

Dimitrios Mistriotis


People also ask

What is C in FreeMarker?

c (when used with numerical value) This built-in converts a number to string for a "computer language" as opposed to for human audience. That is, it formats with the rules that programming languages used to use, which is independent of all the locale and number format settings of FreeMarker.

What is eval in FreeMarker?

eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)

What is FreeMarker spring boot?

FreeMarker is a Java based template engine from the Apache Software Foundation. Like other template engines, FreeMarker is designed to support HTML web pages in applications following the MVC pattern.


2 Answers

The number format you specify must be something that java.text.DecimalFormat supports. The closest thing you can do right now is switching the locale to en_US (and better ensure that it doesn't use groping; see http://freemarker.org/docs/app_faq.html#faq_number_grouping). Or, of course, you can write ?c-s all over, but I suppose that's what you wanted to avoid.

like image 163
ddekany Avatar answered Nov 15 '22 00:11

ddekany


Try with:

cfg.setNumberFormat("#");

It worked for me

like image 41
Carlos Lucas Avatar answered Nov 15 '22 00:11

Carlos Lucas