> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/functions-and-formulas/functions-library/numeric-functions.md).

# Numeric functions

<details>

<summary>NUMBER</summary>

Converts a string representing a number into a decimal number.

**Usage:**

{% code overflow="wrap" %}

```apex
NUMBER(parameter)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with a string you need to convert to decimal.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
NUMBER({Opportunity.Unique_ID__c}) 
```

{% endcode %}

Returns decimal value of `Unique_ID` value, e.g if Unique\_ID = '1234' function will return **1234.0**.

{% hint style="warning" %}
If `Unique_ID` value contains non-digit symbols, the function will throw an exception.
{% endhint %}

</details>

<details>

<summary>INTNUMBER</summary>

Converts a string representing a number into an integer.

**Usage:**

{% code overflow="wrap" %}

```apex
INTNUMBER(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with a string you need to convert to integer.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
INTNUMBER({Opportunity.Unique_Value__c}) 
```

{% endcode %}

Returns integer value of `Unique_Value` value, e.g for Unique\_Value\_\_с = '1234.32' it will return **1234**.

{% hint style="warning" %}
If `Unique_Value__c` value contains non-digit symbols, the function would throw an exception.
{% endhint %}

</details>

<details>

<summary>SUM</summary>

Returns integer or decimal value representing sum of a numeric parameters.

**Usage:**

{% code overflow="wrap" %}

```apex
SUM(list_of_values OR value1, value2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">', etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments.
{% endhint %}

**Example 1:**

<mark style="color:orange;">Let March Amount = 5.5, April Amount = 10 and May Amount = 15.</mark>

{% code overflow="wrap" %}

```apex
SUM({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c}) 
```

{% endcode %}

Returns **30.5**.

**Example 2:**

<mark style="color:orange;">Let String field stores following value: '8, 8, 10, 12'.</mark>

{% code overflow="wrap" %}

```apex
SUM(SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

Returns **48**.

Considering conditions above, the following formula:

{% code overflow="wrap" %}

```apex
SUM({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c}, SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

will return **78.5** (30.5 + 48)

</details>

<details>

<summary>SUB</summary>

Returns integer or decimal value representing result of sequential subtraction.

**Usage:**

{% code overflow="wrap" %}

```apex
SUB(list_of_values OR value1, value2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">, etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments - they will be subtracted first and then results will be subtracted.
{% endhint %}

**Example 1:**

<mark style="color:orange;">Let March Amount = 5, April Amount = 10 and May Amount = 15.</mark>

{% code overflow="wrap" %}

```apex
SUB({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c})
```

{% endcode %}

Returns **-20** (5 - 10 - 15).

**Example 2:**

<mark style="color:orange;">Let String field stores following value: '8, 8, 10, 12'.</mark>

{% code overflow="wrap" %}

```apex
SUB(SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

Returns **-22** (8 - 8 - 10 - 12).

Considering conditions above, the following formula:

{% code overflow="wrap" %}

```apex
SUM({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c}, SPLIT({Stub__c.String__c}, ','))
```

{% endcode %}

will return **2** ((5 - 10 - 15) - (8 - 8 - 10 - 12)).

</details>

<details>

<summary>MULT</summary>

Returns integer or decimal value representing result of multiplication.

**Usage:**

{% code overflow="wrap" %}

```apex
MULT(list_of_values OR value1, value2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">, etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments.
{% endhint %}

**Example 1:**

<mark style="color:orange;">Let March Amount = 5, April Amount = 10 and May Amount = 15.</mark>

{% code overflow="wrap" %}

```apex
MULT({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c}) 
```

{% endcode %}

Returns **750** (5 \* 10 \* 15).

**Example 2:**

<mark style="color:orange;">Let String field stores following value: '8, 8, 10, 12'.</mark>

{% code overflow="wrap" %}

```apex
MULT(SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

Returns **7680** (8 \* 8 \* 10 \* 12).

Considering conditions above, the following formula:

{% code overflow="wrap" %}

```apex
MULT({Stub__c.March_Amount__c}, {Stub__c.April_Amount__c}, {Stub__c.May_Amount__c}, SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

will return **5760000** (750 \* 7680).

</details>

<details>

<summary>DIV</summary>

Returns integer or decimal value representing result of sequential dividing.

**Usage:**

{% code overflow="wrap" %}

```apex
DIV(list_of_values OR value1, value2, ...)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">, etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments - they will be divided first and then results will be divided.
{% endhint %}

**Example 1:**

<mark style="color:orange;">Let x = 450, y = 10 and z = 15.</mark>

{% code overflow="wrap" %}

```apex
DIV({Stub__c.x}, {Stub__c.y}, {Stub__c.z}) 
```

{% endcode %}

Returns **3** (450 / 10 / 15).

**Example 2:**

<mark style="color:orange;">Let String field stores following value: '1200, 2, 10, 12'.</mark>

{% code overflow="wrap" %}

```apex
DIV(SPLIT({Stub__c.String__c}, ',')) 
```

{% endcode %}

Returns **5** (1200 / 2 / 10 / 12).

**Example 3:**

<mark style="color:orange;">Let String field stores following value: '\["24", "2", "3"]' and Area field stores '\["6", "3"]'.</mark>

Considering conditions above, the formula:

{% code overflow="wrap" %}

```apex
DIV(JPARSE({Stub__c.String__c}), JPARSE({Stub__c.Area__c})) 
```

{% endcode %}

will return **2** (((24 / 2) / 3) / (6 / 3)).

</details>

<details>

<summary>SQRT</summary>

Returns the positive square root of a given number.

**Usage:**

{% code overflow="wrap" %}

```apex
SQRT(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the field or expression you want computed into a square root.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
SQRT(26.5)
```

{% endcode %}

Returns **5.1478150704935**, which is a square root of 26.5.

</details>

<details>

<summary>ABS</summary>

Calculates the absolute value of a number. The absolute value of a number is the number without its positive or negative sign.

**Usage:**

{% code overflow="wrap" %}

```apex
ABS(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with a field or numeric value that has the sign you want removed.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
ABS({Department__c.Expected_Revenue__c}) 
```

{% endcode %}

Returns the calculated positive value of the Expected Revenue amount regardless of whether it is positive or negative.

</details>

<details>

<summary>LOG</summary>

Returns the base 10 logarithm of a number.

**Usage:**

{% code overflow="wrap" %}

```apex
LOG(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the field or expression from which you want the base 10 logarithm calculated.</mark>*

**Example:**

<mark style="color:orange;">Let {$Variables.Concentration} = 10</mark><sup><mark style="color:orange;">-6<mark style="color:orange;"></sup><mark style="color:orange;">.</mark>

{% code overflow="wrap" %}

```apex
LOG({$Variables.Concentration}) 
```

{% endcode %}

Returns **-6**.

</details>

<details>

<summary>POW</summary>

Returns one value `X` raised to the power of another value `Y`, i.e. `X`<sup>`Y`</sup>.

**Usage:**

{% code overflow="wrap" %}

```apex
POW(parameter, exponent)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">argument with integer or double value that needs to be raised to the power of</mark>* *<mark style="color:cyan;">`exponent`</mark>* *<mark style="color:cyan;">argument.</mark>*

**Example 1:**

{% code overflow="wrap" %}

```apex
POW (8, 3)
```

{% endcode %}

Returns **512** (8<sup>3</sup>).

**Example 2:**

{% code overflow="wrap" %}

```apex
POW (1000, -1/3)
```

{% endcode %}

Returns **0.1** (1000<sup>-1/3</sup>).

</details>

<details>

<summary>MOD</summary>

Returns a remainder after a number is divided by a specified divisor.

**Usage:**

{% code overflow="wrap" %}

```apex
MOD(parameter1, parameter2)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`parameter1`</mark>* *<mark style="color:cyan;">with the field or expression you want to be divided</mark>*
* *<mark style="color:cyan;">`parameter2`</mark>* *<mark style="color:cyan;">with the number to use as the divisor</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
MOD(123, 100) 
```

{% endcode %}

Returns **23**.

</details>

<details>

<summary>MIN</summary>

Returns the lowest number from several numeric values.

**Usage:**

{% code overflow="wrap" %}

```apex
MIN(list_of_values OR value1, value2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">, etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments.
{% endhint %}

**Example:**

<mark style="color:orange;">Let String field stores following value: '\["12", "2", "3"]' and Area field stores '\["6", "3"]'.</mark>

{% code overflow="wrap" %}

```apex
MIN(JPARSE({Stub__c.String__c}), JPARSE({Stub__c.Area__c})) 
```

{% endcode %}

Returns **2**.

</details>

<details>

<summary>MAX</summary>

Returns the highest number from several numeric values.

**Usage:**

{% code overflow="wrap" %}

```apex
MAX(list_of_values OR value1, value2, ...) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`list_of_values`</mark>* *<mark style="color:cyan;">argument with the list of numeric values or pass numeric values as</mark>* *<mark style="color:cyan;">`value1`</mark><mark style="color:cyan;">,</mark>* *<mark style="color:cyan;">`value2`</mark><mark style="color:cyan;">, etc. arguments.</mark>*

{% hint style="info" %}
You can also pass combination of arrays and separate numeric arguments.
{% endhint %}

**Example:**

<mark style="color:orange;">Let String field stores following value: '\["12", "2", "3"]' and Area field stores '\["6", "3"]'.</mark>

{% code overflow="wrap" %}

```apex
MAX(JPARSE({Stub__c.String__c}), JPARSE({Stub__c.Area__c}), 9, 13) 
```

{% endcode %}

Returns **13**.

</details>

<details>

<summary>ROUND</summary>

Returns the rounded approximation of a decimal value.

**Usage:**

{% code overflow="wrap" %}

```apex
ROUND(decimal_value, CEILING|DOWN|FLOOR|UP|HALF_DOWN|HALF_UP)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`decimal_value`</mark>* *<mark style="color:cyan;">with the decimal to be rounded</mark>*

*<mark style="color:cyan;">Pass one of the allowed rounding modes (CEILING, FLOOR, DOWN, UP, HALF\_DOWN, HALF\_UP)</mark>*

**Examples:**

`ROUND(122.3456669, 'CEILING')` will return **123**.\
`ROUND(-122.3456669, 'CEILING')` will return **-122**.

`ROUND(122.3456669, 'FLOOR')` will return **122**.\
`ROUND(-122.3456669, 'FLOOR')` will return **-123**.

`ROUND(122.3456669, 'DOWN')` will return **122**.\
`ROUND(-122.3456669, 'DOWN')` will return **-122**.

`ROUND(122.3456669, 'UP')` will return **123**.\
`ROUND(-122.3456669, 'UP')` will return **-123**.

`ROUND(122.5, 'HALF_DOWN')` will return **122**.\
`ROUND(122.5, 'HALF_UP')` will return **123**.\
`ROUND(-122.5, 'HALF_DOWN')` will return **-122**.\
`ROUND(-122.5, 'HALF_UP')` will return **-123**.

</details>

<details>

<summary>SCALE</summary>

Returns the decimal scaled to the specified number of decimal places.

**Usage:**

{% code overflow="wrap" %}

```apex
SCALE(decimal_value, decimal_places) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`decimal_value`</mark>* *<mark style="color:cyan;">with decimal value you want scaled</mark>*
* *<mark style="color:cyan;">`decimal_places`</mark>* *<mark style="color:cyan;">with number of decimal places to be left</mark>*

**Example 1:**

<mark style="color:orange;">Let salary value is 122.3456669.</mark>

{% code overflow="wrap" %}

```apex
SCALE({User.Salary__c}, 2) 
```

{% endcode %}

Returns **122.35**.

**Example 2:**

<mark style="color:orange;">Let number value is 25.</mark>

{% code overflow="wrap" %}

```apex
SCALE({Stub__c.Number__c}, 3) 
```

{% endcode %}

Returns **25.000**.

</details>

<details>

<summary>RANDOM</summary>

Generates a random 19-digit number (positive or negative; negative number will also have a sign).

**Usage:**

{% code overflow="wrap" %}

```apex
RANDOM() 
```

{% endcode %}

{% hint style="info" %}
Doesn't require parameters.
{% endhint %}

**Example:**

{% code overflow="wrap" %}

```apex
RANDOM() 
```

{% endcode %}

Can return **2139744657709176245** or **-6535028942888403203** (a random 19-digit number).

</details>

<details>

<summary>FORMATNUMBER</summary>

Formats the decimal value to make it have readable view (adds thousands separators and removes leading zeroes) using the locale of the context user.

**Usage:**

{% code overflow="wrap" %}

```apex
FORMATNUMBER(decimal_value) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`decimal_value`</mark>* *<mark style="color:cyan;">with decimal value you want to be formatted.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
FORMATNUMBER(-01233534343453.566) 
```

{% endcode %}

Returns **-1,233,534,343,453.566** for the user with US locale.

</details>
