Numeric Functions within Freemarker


There are times when you may wish to control the output format of a numeric field within your Java Servlet Applications. Freemarker allows you to do this easily directly within the m-Painter environment. To add these functions, simply open m-Painter and right click on the Field you wish to modify. Select the “Application Field Properties” option. Add the Numeric Function into the “Representation” box in the correct location. When completed, hit OK. Then be sure to save your application.

One of the most useful options available to Numeric Fields within Freemarker is the ability to apply formatting directly within the source of the HTML.

Modifying into a String

The use of the “?string” option is vital. Numeric values such as 1000000 are easy for a computer to understand, but difficult for a human because the zeros run together. However, written like 1,000,000 is very easy for a human to read. Similarly, if a value is smaller than 1E-16 (a number with more than 16 positions to the right of the decimal place) it would be rounded to zero, whereas a string function would display the true value. Converting this value to a string allows the JVM installed to control the look of the value based upon the location. European JVMs could render a value formatting slightly different than a US JVM due to the location.

As an example, let’s say that I have a field with a value equal to 1234. If no Edit Code is selected within m-Power, my output will look like this:

Next, I will illustrate the two most popular Freemarker Formatting options: Number & Currency:

My normal field substitution looks like this:

${row.OTHERSS?html} — This outputs the text 1234 (This is the default code generated by m-Power).

${row.OTHERSS_o?string.number} — This outputs the text 1,234.

${row.OTHERSS_o?string.currency} — This outputs the text $1,234.00.

_o — This specifies to Freemarker that this is a numeric field, capable of allowing string manipulation.

string.number — This specifies to treat this field like a normal, numeric field (Using commas and periods where necessary).

string.currency — This specifies to treat this field to display like money (The use of $, commas and period where necessary).

If you are located outside of the US, your string.number and string.currency will display differently as your JVM is written specifically for your country’s standards.

Freemarker Formatting codes will take precedence over m-Power Edit Codes.

To learn even more Advanced Formatting for Numeric Fields, click here.

Updated on September 30, 2021

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support