Leer en inglés

Compartir a través de

Bicep 数字运算符

数值运算符使用整数执行计算并返回整数值。 若要运行示例,请使用 Azure CLI 或 Azure PowerShell 部署 Bicep 文件

操作员 名称
* Multiply
/
%
+ 添加
-
- 减去

Nota

减去和减号使用相同的运算符。 功能不同,因为减法使用两个作数,减法使用一个作数。

乘*

operand1 * operand2

将两个整数相乘。

操作数

操作数 类型 DESCRIPTION
operand1 整数 要相乘的数字。
operand2 整数 数字的乘数。

返回值

乘法将乘积作为整数返回。

示例:

两个整数相乘并返回乘积。

param firstInt int = 5
param secondInt int = 2

output product int = firstInt * secondInt

示例中的输出:

名称 类型 价值
product 整数 10

分/

operand1 / operand2

将整数除以整数。

操作数

操作数 类型 DESCRIPTION
operand1 整数 除法的整数。
operand2 整数 用于除法的整数。 不能为零。

返回值

除法将商作为整数返回。

示例:

两个整数被除以并返回商。

param firstInt int = 10
param secondInt int = 2

output quotient int = firstInt / secondInt

示例中的输出:

名称 类型 价值
quotient 整数 5

Modulo %

operand1 % operand2

将整数除以整数并返回余数。

操作数

操作数 类型 DESCRIPTION
operand1 整数 被除的整数。
operand2 整数 用于除法的整数。 不能为 0。

返回值

余数以整数的形式返回。 如果除法不生成余数,则返回 0。

示例:

两对整数被除以并返回余数。

param firstInt int = 10
param secondInt int = 3

param thirdInt int = 8
param fourthInt int = 4

output remainder int = firstInt % secondInt
output zeroRemainder int = thirdInt % fourthInt

示例中的输出:

名称 类型 价值
remainder 整数 1
zeroRemainder 整数 0

添加 +

operand1 + operand2

添加两个整数。

操作数

操作数 类型 DESCRIPTION
operand1 整数 要添加的数字。
operand2 整数 添加到数字的数字。

返回值

加法将求和作为整数返回。

示例:

添加两个整数并返回总和。

param firstInt int = 10
param secondInt int = 2

output sum int = firstInt + secondInt

示例中的输出:

名称 类型 价值
sum 整数 12

减去-

operand1 - operand2

从整数中减去整数。

操作数

操作数 类型 DESCRIPTION
operand1 整数 从中减去的较大数字。
operand2 整数 从较大的数字中减去的数字。

返回值

减法以整数的形式返回差值。

示例:

一个整数被减去并返回差异。

param firstInt int = 10
param secondInt int = 4

output difference int = firstInt - secondInt

示例中的输出:

名称 类型 价值
difference 整数 6

减去-

-integerValue

将整数乘以 -1

操作数

操作数 类型 DESCRIPTION
integerValue 整数 整数乘以 -1

返回值

整数乘以 -1。 正整数返回负整数,负整数返回正整数。 这些值可以用括号包装。

示例:

param posInt int = 10
param negInt int = -20

output startedPositive int = -posInt
output startedNegative int = -(negInt)

示例中的输出:

名称 类型 价值
startedPositive 整数 -10
startedNegative 整数 20

后续步骤