Example of Formatting a Number Using a Formatter
To format a number numberVal as a floating point value with two (2) decimal places and thousands separator you can do:
Double dv = numberVal as Double
def fmt = new Formatter(adf.context.locale)
def ret = (dv != null) ? fmt.format('%,.2f', dv) : null
If the value of numberVal
were 12345.6789
, and the
current user's locale is US English, then this would produce a formatted string
like:
12,345.68
If instead the current user's locale is Italian, it would produce a formatted string like:
12.345,68
To format a number numberVal
as a floating point value with three (3)
decimal places and no thousands separator you can do:
Double dv = numberVal as Double
def fmt = new Formatter(adf.context.locale)
def ret = (dv != null) ? fmt.format('%.3f', dv) : null
If the value of numberVal
were 12345.6789
, and the
current user's locale is US English, then this would produce a formatted string
like:
12345.679
To format a number value with no decimal places to have a zero-padded width of 8, you can do:
Long lv = numberVal as Long
def fmt = new Formatter(adf.context.locale)
def ret = (lv != null) ? fmt.format('%08d', lv) : null
If the value of numberVal
were 5543
, then this would
produce a formatted string like:
00005543