Math Formatters

Version 23.4.8839


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 executes 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, that value is returned instead of true (if the input is greater than value), and if ifnotgreater is supplied, that value is 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, that value is returned instead of true (if the input is less than value), and if ifnotless is supplied, that value is 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 input attribute is required.

Example

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

Other Math Formatters

The following formatters are less common than those described 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: An optional number specifying how many places to the right of the decimal to display. The default is 2.

decimal([integer_count])

Returns the numeric value formatted as a decimal number, with commas to delimit thousands, millions, and so on.

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

div([value])

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

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

divide([value])

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

  • value: An optional numeric value to divide the numeric attribute value by. The 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

<arc: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 is $1440.12.

<arc: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 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. Otherwise it returns false (or ifnotbetween).

  • 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. Otherwise it returns false (or ifnotequal).

  • 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: An optional number that indicates how many places to the right of the decimal to display.

pow([value])

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

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

round([integer_value])

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

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

Note: The rounding strategy used is based on your operating system. .NET uses Midpoint Rounding, and Java uses Half Even.

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.