- 3 minutes to read

Formula - Round (round)

New 7.12 The round function, one of the Math functions in the Formula plugin for Search Field Expressions, returns every numeric value in the content rounded to the number of decimals you give, with midpoints rounded away from zero.

Test Expression tab: round of the average of the order line totals, with 2 decimals, returns 340.93 (7.12)
The typical use: avg keeps up to 28 decimals, and round(…, 2) cuts the average line total of order ORD-10011 in the Order-to-Cash demo to 340.93.

Syntax

round(content, decimals)

Parameters

Parameter Required Description
content ✅ Yes The numeric values to round: body, context, or another Formula function, typically avg, sum, xPath, jsonPath, or csv.
decimals ✅ Yes An unquoted whole number from 0 to 28: the number of decimals to keep.

round has no unique argument: it doesn't aggregate, so the unique rule of the other Math functions doesn't apply.

Returns

  • Every numeric value in content, each rounded on its own to decimals decimals. Several values in give several values out.
  • A midpoint is rounded away from zero: 2.5 → 3, -2.5 → -3, and 2.345 with 2 decimals → 2.35.
  • The value isn't padded: 1.5 rounded to 2 decimals stays 1.5, and trailing zeros already in a value stay (399.80 with 2 → 399.80).
  • A value that isn't a number is dropped, as with avg, min, and max. When nothing numeric is left, round returns nothing.
  • The decimal separator is always ., whatever the culture of the server.

Quoting, nesting, and how content is resolved are described in the Formula language rules.

Examples

Example 1: Round the average line total of an order

Input

Message Body:

<OrderEntry>
  <OrderId>ORD-10011</OrderId>
  <OrderLines>
    <OrderLine><Sku>SKU-1001</Sku><LineTotal>399.80</LineTotal></OrderLine>
    <OrderLine><Sku>SKU-2040</Sku><LineTotal>498.00</LineTotal></OrderLine>
    <OrderLine><Sku>SKU-3315</Sku><LineTotal>125.00</LineTotal></OrderLine>
  </OrderLines>
</OrderEntry>

Formula

round(avg(xPath('OrderEntry/OrderLines/OrderLine/LineTotal', body)), 2)

Result

340.93

xPath extracts the line totals 399.80, 498.00, and 125.00. avg returns 340.9333333333333333333333333 (1022.80 / 3), and round keeps two decimals. The screenshot of this example is at the top of the page.

Example 2: Round several values, midpoints away from zero

Input

Message Body:

{ "a": [ { "b": 2.5 }, { "b": -2.5 }, { "b": 1.4 } ] }

Formula

round(jsonPath('a[*].b', body), 0)

Result

3
-3
1

Test Expression tab: round of every b in the array a, with 0 decimals, returns 3, minus 3, and 1 (7.12)
jsonPath extracts three values and round rounds each one: the midpoints 2.5 and -2.5 go away from zero, to 3 and -3.

Notes

  • Both arguments are required. round(avg(...)) without the decimals is a syntax error: Expected the number of decimals, for example round(avg(...), 2), found ....
  • Decimals outside 0 to 28 are an error: round expects 0 to 28 decimals.
  • Midpoints round away from zero, not to the nearest even number (banker's rounding): 0.5 → 1, 1.5 → 2, 2.5 → 3.

Next Steps