On This Page
advertisement

The transforms in this category perform mathematical functions on values:

Transform Description
mathAbs Returns the absolute value of a number
mathAdd Adds a number to the value
mathCeiling Rounds the value to the smallest integer greater than or equal to the value
mathDivide Divides the value by the given divisor
mathFloor Rounds the value to the largest integer less than or equal to the value
mathMultiply Multiplies the value by the given factor
mathRound Rounds the value to the nearest integer
mathSubtract Subtracts a number from the value

Leading Zeroes

To perform math operations, ORA converts text values to numbers and the conversion drops any leading zeroes. For example, if a field named ImageNumber has the value "00183", the result of [ImageNumber:mathAdd:1] is "184".

If you need a number padded on the left with zeroes, use the padLeft transform.

Remove Leading Zeroes

Because ORA converts text values to numbers and that conversion removes leading zeroes, you may use mathAdd to remove leading zeroes without incrementing the number: just add zero! For example, if a field named ImageNumber has the value "00183", the result of [ImageNumber:mathAdd:0] is "183".

Trailing Zeroes

To perform math operations, ORA converts text values to numbers and that conversion drops any trailing zeroes in the fractional part of a real number. For example, if a field named Price has the value "1.20", the result of [Price:mathAdd:1] is "2.2".

As you can see from the example, the trailing zero has been removed. You may want to retain a certain number of digits after the decimal point, or convert numbers with a varying number of digits to the same number of digits by padding with zeroes. Unfortunately, padding to a certain number of digits after a decimal point is not directly supported by an ORA transform and manual methods are tricky. The replace transform will suffice in some cases though its fragile as a general-purpose solution. The basic idea is to use a replacement pattern that matches a value that needs a trailing zero then replace the matching text with the original text and an extra zero.

For example, if you want a field named Rate to have two digits after the decimal point, where some values have two digits ("1.25") and others have one digit ("1.2"), you can match the one-digit values and replace them with the original digit and a trailing zero:

[Rate:replace:(?<v>\.\d)$:$<v>0:g]

The pattern "(?<v>\.\d)$" matches a period followed by a single digit at the end of the Field value. The parentheses and the special "?<v>" notation create a named capture group with the name "v". Typically, we can use capture groups that are automatically numbered sequentially, but in this case, we want to use the capture group followed by a digit in the replacement value. Without using a named capture group, the transform would look like this, and it would not work:

[Rate:replace:(.\d)$:$10:g]

To the Regular Expression parser, "$10" in the replacement value looks like a reference to capture group ten, not a reference to capture group one followed by a zero. To get around that issue, the working example uses a named capture group and that requires the use of "?<v>" to name the group and "$<v>" to refer to it.

mathAbs

Returns the absolute value of a number.

For example, if a Field named Difference has the value "-3", the result of [Difference:mathAbs] is "3".

If the value is not numeric, returns an empty string.

mathAdd:number

Adds a number to the value.

For example, if a field named ImageNumber has the value "00813", the result of [ImageNumber:mathAdd:1] is "814".

If the value or the number is not numeric, returns an empty string.

mathCeiling

Rounds the value to the smallest integer greater than or equal to the value.

For example, if a field named Age has the value "3.2", the result of [Age:mathCeiling] is "4".

If the value is not numeric, returns an empty string.

See: mathFloor, mathRound

mathDivide:divisor

Divides the value by the given divisor.

For example, if a field named Weeks has the value "18", the result of [Weeks:mathDivide:4] is "4.5".

If the value or the divisor is not numeric, or if the divisor is zero, returns an empty string.

mathFloor

Rounds the value to the largest integer less than or equal to the value.

For example, if a field named Age has the value "3.2", the result of [Age:mathFloor] is "3".

If the value is not numeric, returns an empty string.

See: mathCeiling, mathRound

mathMultiply:factor

Multiplies the value by the given factor.

For example, if a field named Weeks has the value "4", the result of [Weeks:mathMultiply:7] is "28".

If the value or the factor is not numeric, returns an empty string.

mathRound

Rounds the value to the nearest integer.

For example, if a field named Age has the value "3.4", the result of [Age:mathRound] is "3". If a field named Age has the value "3.5", the result of [Age:mathRound] is "4".

If the value is not numeric, returns an empty string.

See: mathCeiling, mathFloor

mathSubtract:number

Subtracts a number from the value.

For example, if a field named ImageNumber has the value "00813", the result of [ImageNumber:mathSubtract:1] is "812".

If the value or the number is not numeric, returns an empty string.