Working with numbers
math
helper performs common arithmetic operations. It can accept integers, decimals
or strings as its operands and will always yield a number as its output rather than a string.
Addition, subtraction, multiplication, division and remainder (mod) are supported.
numberFormat
helper allows you to specify how numbers are printed. It supports
a number of predefined formats, custom format strings and various other options
including rounding mode, decimal places and locale.
numberFormat
supports the following predefined formats:
integer
currency
percent
£123.46
.
Alternatively, if we wanted to output the number as a percentage:
12,346%
.
123.456700
.
See the Java DecimalFormat documentation
for details on how to use format strings.
maximumFractionDigits
, minimumFractionDigits
, maximumIntegerDigits
, minimumIntegerDigits
.
234.567000
.
numberFormat
will insert commas, periods etc. per the locale between
groups of digits e.g. 1,234.5
.
This behaviour can be disabled with groupingUsed
.
12345.678
.
roundingMode
parameter affects how numbers will be rounded up or down when
it’s necessary to do so.
For instance, to always round down:
1.23
.
Available rounding modes are:
up
down
half_up
half_down
half_even
ceiling
floor
.