Numeric functions for ARM templates
Resource Manager provides the following functions for working with integers in your Azure Resource Manager template (ARM template):
Tip
We recommend Bicep because it offers the same capabilities as ARM templates and the syntax is easier to use. To learn more about using int
, min
, and max
in Bicep, see numeric functions. For other numeric values, see numeric operators.
add(operand1, operand2)
Returns the sum of the two provided integers.
The add
function isn't supported in Bicep. Use the +
operator instead.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | First number to add. |
operand2 | Yes | int | Second number to add. |
An integer that contains the sum of the parameters.
The following example adds two parameters.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 5,
"metadata": {
"description": "First integer to add"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Second integer to add"
}
}
},
"resources": [
],
"outputs": {
"addResult": {
"type": "int",
"value": "[add(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
addResult | Int | 8 |
copyIndex(loopName, offset)
Returns the index of an iteration loop.
In Bicep, use iterative loops.
Parameter | Required | Type | Description |
---|---|---|---|
loopName | No | string | The name of the loop for getting the iteration. |
offset | No | int | The number to add to the zero-based iteration value. |
This function is always used with a copy object. If no value is provided for offset, the current iteration value is returned. The iteration value starts at zero.
The loopName property enables you to specify whether copyIndex is referring to a resource iteration or property iteration. If no value is provided for loopName, the current resource type iteration is used. Provide a value for loopName when iterating on a property.
For more information about using copy, see:
- Resource iteration in ARM templates
- Property iteration in ARM templates
- Variable iteration in ARM templates
- Output iteration in ARM templates
The following example shows a copy loop and the index value included in the name.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageCount": {
"type": "int",
"defaultValue": 2
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[format('{0}storage{1}', range(0, parameters('storageCount'))[copyIndex()], uniqueString(resourceGroup().id))]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {},
"copy": {
"name": "storagecopy",
"count": "[parameters('storageCount')]"
}
}
]
}
An integer representing the current index of the iteration.
div(operand1, operand2)
Returns the integer division of the two provided integers.
The div
function isn't supported in Bicep. Use the /
operator instead.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number being divided. |
operand2 | Yes | int | The number that is used to divide. Can't be 0. |
An integer representing the division.
The following example divides one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 8,
"metadata": {
"description": "Integer being divided"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer used to divide"
}
}
},
"resources": [
],
"outputs": {
"divResult": {
"type": "int",
"value": "[div(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
divResult | Int | 2 |
float(arg1)
Converts the value to a floating point number. You only use this function when passing custom parameters to an application, such as a Logic App.
The float
function isn't supported in Bicep.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | string or int | The value to convert to a floating point number. |
A floating point number.
The following example shows how to use float to pass parameters to a Logic App:
{
"type": "Microsoft.Logic/workflows",
"properties": {
...
"parameters": {
"custom1": {
"value": "[float('3.0')]"
},
"custom2": {
"value": "[float(3)]"
},
int(valueToConvert)
Converts the specified value to an integer.
In Bicep, use the int function.
Parameter | Required | Type | Description |
---|---|---|---|
valueToConvert | Yes | string or int | The value to convert to an integer. |
An integer of the converted value.
The following example template converts the user-provided parameter value to integer.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"stringToConvert": {
"type": "string",
"defaultValue": "4"
}
},
"resources": [
],
"outputs": {
"intResult": {
"type": "int",
"value": "[int(parameters('stringToConvert'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
intResult | Int | 4 |
max(arg1)
Returns the maximum value from an array of integers or a comma-separated list of integers.
In Bicep, use the max function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array of integers, or comma-separated list of integers | The collection to get the maximum value. |
An integer representing the maximum value from the collection.
The following example shows how to use max with an array and a list of integers.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"arrayToTest": {
"type": "array",
"defaultValue": [ 0, 3, 2, 5, 4 ]
}
},
"resources": [],
"outputs": {
"arrayOutput": {
"type": "int",
"value": "[max(parameters('arrayToTest'))]"
},
"intOutput": {
"type": "int",
"value": "[max(0,3,2,5,4)]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Int | 5 |
intOutput | Int | 5 |
min(arg1)
Returns the minimum value from an array of integers or a comma-separated list of integers.
In Bicep, use the min function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array of integers, or comma-separated list of integers | The collection to get the minimum value. |
An integer representing minimum value from the collection.
The following example shows how to use min with an array and a list of integers.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"arrayToTest": {
"type": "array",
"defaultValue": [ 0, 3, 2, 5, 4 ]
}
},
"resources": [],
"outputs": {
"arrayOutput": {
"type": "int",
"value": "[min(parameters('arrayToTest'))]"
},
"intOutput": {
"type": "int",
"value": "[min(0,3,2,5,4)]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Int | 0 |
intOutput | Int | 0 |
mod(operand1, operand2)
Returns the remainder of the integer division using the two provided integers.
The mod
function isn't supported in Bicep. Use the % operator instead.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number being divided. |
operand2 | Yes | int | The number that is used to divide, Can't be 0. |
An integer representing the remainder.
The following example returns the remainder of dividing one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 7,
"metadata": {
"description": "Integer being divided"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer used to divide"
}
}
},
"resources": [
],
"outputs": {
"modResult": {
"type": "int",
"value": "[mod(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
modResult | Int | 1 |
mul(operand1, operand2)
Returns the multiplication of the two provided integers.
The mul
function isn't supported in Bicep. Use the * operator instead.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | First number to multiply. |
operand2 | Yes | int | Second number to multiply. |
An integer representing the multiplication.
The following example multiplies one parameter by another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 5,
"metadata": {
"description": "First integer to multiply"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Second integer to multiply"
}
}
},
"resources": [
],
"outputs": {
"mulResult": {
"type": "int",
"value": "[mul(mul(parameters('first'), parameters('second')), 3)]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
mulResult | Int | 45 |
sub(operand1, operand2)
Returns the subtraction of the two provided integers.
The sub
function isn't supported in Bicep. Use the - operator instead.
Parameter | Required | Type | Description |
---|---|---|---|
operand1 | Yes | int | The number that is subtracted from. |
operand2 | Yes | int | The number that is subtracted. |
An integer representing the subtraction.
The following example subtracts one parameter from another parameter.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"first": {
"type": "int",
"defaultValue": 7,
"metadata": {
"description": "Integer subtracted from"
}
},
"second": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Integer to subtract"
}
}
},
"resources": [
],
"outputs": {
"subResult": {
"type": "int",
"value": "[sub(parameters('first'), parameters('second'))]"
}
}
}
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
subResult | Int | 4 |
- For a description of the sections in an ARM template, see Understand the structure and syntax of ARM templates.
- To iterate a specified number of times when creating a type of resource, see Resource iteration in ARM templates.