Math Formatters

Version 22.0.8473


Math Formatters


Common Math Formatters

The following formatters are the most common math formatters. An example for each formatter is provided for reference.

add(value)

Adds the input attribute/value to the value parameter and returns the result.

Example

<!-- count the number of loops in an XML document using xmlDOMSearch -->

<arc:set attr="xml.uri" value="[FilePath]" />
<arc:set attr="xml.xpath" value="/Items/test/loop" />

<arc:call op="xmlDOMSearch" in="xml">
  <!-- this code will execute for each occurrence of the 'xpath' in the XML document -->
  <arc:set attr="loopCount" value="[loopCount | def(0) | add(1)]" />
</arc:call>

greaterthan(value[, ifgreater][, ifnotgreater])

Returns true if the input attribute/value is greater than the value parameter, and false otherwise.

If ifgreater is supplied, then that value will be returned instead of true (if the input is greater than value), and if ifnotgreater is supplied, then that value will be returned instead of false (if the input is not greater than value).

Example

<arc:set attr="totalCost" value="[xpath(Items/Order/TotalCost)]" />
<arc:if exp="[totalCost | greaterthan(1000)]">
  <arc:set attr="highValueOrder" value="true" />
</arc:if>

lessthan(value[, ifless][, ifnotless])

Returns true if the input attribute/value is less than the value parameter, and false otherwise.

If ifless is supplied, then that value will be returned instead of true (if the input is less than value), and if ifnotless is supplied, then that value will be returned instead of false (if the input is not less than value).

Example

<arc:set attr="totalCost" value="[xpath(Items/Order/TotalCost)]" />
<arc:if exp="[totalCost | lessthan(0)]">
  <arc:throw code="1" desc="ERROR: Invalid order total." />
</arc:if>

multiply(value)

Multiplies the input attribute/value with the value parameter and returns the result.

Example

<!-- find the total cost by multiplying the price and the quantity of a purchased item -->
<arc:set attr="item.price" value="[xpath(lineitem/costperunit)]" />
<arc:set attr="item.quantity" value="[xpath(lineitem/quantitypurchased)]" />
<arc:set attr="item.totalcost" value="[item.price | multiply([item.quantity])]" />

rand(upperBound)

Generates a random integer between 0 and upperBound.

This formatter does not modify the input attribute (variable), so no such input attribute is required.

Example

<!-- add a random number to the end of a filename -->
<arc:set attr="myFilename" value="myfile-[rand(100000)].xml" />

More Math Formatters

Below is the list of less-common formatters not included in the previous section.

abs()

Returns the absolute value of the numeric attribute value.

and(value)

Returns the AND of two values. The values provided on each side must be 1/0, yes/no or true/false.

  • value: The boolean value to compare by.

ceiling()

Returns the smallest integer greater than or equal to a numeric attribute value.

currency([integer_count])

Returns the numeric value formatted as currency.

  • count: The optional number specifying how many places to the right of the decimal are displayed. The default is 2.

decimal([integer_count])

Returns the numeric value formatted as a decimal number; adds commas to delimit the thousands, millions, etc.

  • count: The optional number that indicates how many places to the right of the decimal are displayed. Default is 2.

div([value])

Returns the result of dividing the numeric attribute value by the specified value of the parameter.

  • value: The optional numeric value to divide the numeric attribute value by. Default is 2.

divide([value])

Returns the result of dividing the numeric attribute value by the specified value of the parameter.

  • value: The optional numeric value to divide the numeric attribute value by. Default is 2.

expr(expression)

Evaluates the mathematical expression.

  • expression: The expression.

floor()

Returns the largest integer less than or equal to the numeric attribute value.

format(“pattern”)

Formats a numerical result based on the provided pattern and the platform’s behavior.

  • pattern: The formatting pattern to use.

Examples

<rsb:set attr="tmp" value="$1,440.123" />
[tmp]
<br>
[tmp | format("#.##")]

The tmp attribute, set to $1,440.123, is passed through the format("#.##") formatter. The result in this case is 1440.12.

<rsb:set attr="rnd" value="1055.68" />
[rnd]
<br>
[rnd | format("#.#")]

The rnd attribute, set to 1055.68, is passed through the format("#.#") formatter. The result in this case is 1055.7.

isbetween(integer_lowvalue, integer_highvalue[, ifbetween][, ifnotbetween])

Returns true (or ifbetween) if the attribute value is greater than or equal to the first parameter value and less than or equal to the second parameter value, false (or ifnotbetween) otherwise.

  • lowvalue: The lower bound of the range to check.
  • highvalue: The higher bound of the range to check.
  • ifbetween: The optional value returned if the attribute value is greater than or equal to the first parameter value and less than or equal to the second parameter value.
  • ifnotbetween: The optional value returned if the attribute value is less than the first parameter value or greater than the second parameter value.

isequal(value[, ifequal][, ifnotequal])

Returns true (or ifequal) if the attribute value is equal to the parameter value, false (or ifnotequal) otherwise.

  • value: The numeric value to compare with the attribute value.
  • ifequal: The optional value returned if the attribute value is equal to the parameter value.
  • ifnotequal: The optional value returned if the attribute value is not equal to the parameter value.

modulus(value)

Returns the modulus of the numeric attribute value divided by the specified parameter value.

  • value: The number to divide the attribute value by.

or(value)

Returns the OR of two values. The values provided on each side must be 1/0, yes/no or true/false.

  • value: The boolean value to compare by.

percentage([integer_count])

Returns the numeric value formatted as a percentage.

  • count: The optional number that indicates how many places to the right of the decimal are displayed.

pow([value])

Returns the numeric attribute value raised to the power specified by the parameter value.

  • value: The optional power to raise the attribute value to. Default is 2.

round([integer_value])

Returns the numeric attribute value rounded to the number of decimal places specified by the parameter.

  • value: The optional number of decimal places. Default is 2.

sqrt()

Returns the square root of the numeric attribute value.

subtract([value])

Returns the difference between the numeric attribute value and the value specified by the parameter.

  • value: The optional numeric value to subtract the attribute value by.