Numeric Transformers
Numeric transformers can be used on the source type of Number
- Int
, Float
or Double
. Following transformers are available:
addedBy
addedBy
Returns result of the addition of the source and value
. value
is considered Double
.
Usage:
.addedBy(value)
Example usage:
value.addedBy(15.5)
Example return:
10
to25.5
dividedBy
dividedBy
Returns result of the division of the source and value
. value
is considered Double
. Note: Division by zero is handled gracefully, produces zero, and doesn't throw an error.
Usage:
.dividedBy(value)
Example usage:
value.dividedBy(2.5)
Example return:
5
to2
multipliedBy
multipliedBy
Returns result of multiplication of the source and value
. value
is considered Double
.
Usage:
.multipliedBy(value)
Example usage:
value.multipliedBy(4)
Example return:
2
to8
subtractedBy
subtractedBy
Returns result of subtraction of the source and value
. value
is considered Double
.
Usage:
.subtractedBy(value)
Example usage:
value.subtractedBy(2)
Example return:
25
to23
rounded
rounded
Returns the source rounded to specified number of fractions. value
must be Int
.
Usage:
.rounded(fractions)
Example usage:
value.rounded(1)
Example return:
1.11
to1
or1.16
to1.2
ceiled
ceiled
Returns the next highest Int
by rounding up the source if necessary.
Usage:
.ceiled()
Example usage:
value.ceiled()
Example return:
1.78
to2
or-3.14
to-3
floored
floored
Returns the next lowest Int
by rounding up the source if necessary.
Usage:
.floored()
Example usage:
value.floored()
Example return:
1.78
to1
or-3.14
to-4
absolute
absolute
Returns absolute source
Usage:
.default(value)
Example usage:
value.default("Empty")
Example return:
` to
Empty`
positive
positive
Returns the source that is either the same if it was >0
, or multiplied by -1
if it was <0
.
Usage:
.positive()
Example usage:
value.positive()
Example return:
-1
to1
or2
to -2`
negative
negative
Returns the source that is either the same if it was <0
, or multiplied by -1
if it was >0
.
Usage:
.negative()
Example usage:
value.negative()
Example return:
1
to-1
or-2
to-2
formatDate
formatDate
Returns formatted date. The source must be Int
holding value of standard time interval since 1970 (Unix epoch time).
Usage:
.formatDate(format)
Example usage:
value.formatDate("YYYY-MM-DD")
Example return:
1587490511
to2020-04-21
Last updated
Was this helpful?