Formatting Numbers and Dates Using a Formatter

Groovy provides the Formatter object that you can use in a text formula expression or anywhere in your scripts that you need for format numbers or dates.

The general pattern for using a Formatter is to first construct a new instance like this, passing the the expression for the current user's locale as an argument:

def fmt = new Formatter(adf.context.locale)

This Formatter object you've instantiated will generally be used to format a single, non-null value by calling its format() method like this:

def ret = fmt.format( formatString , arg1 [, arg2 , ..., argN ] )

Note that if you call the format() method of the same Formatter object multiple times, then the results are concatenated together. To format several distinct values without having their results be concatentated, instantiate a new Formatter for each call to a format() method.

The format string can include a set of special characters that indicate how to format each of the supplied arguments. Some simple examples are provided below, however the complete syntax is covered in the documentation for the Formatter class.