概要
傳回兩個整數除法的商數。
語法
div(<operands>)
描述
函 div() 式會傳回兩個整數除法的商數。 如果除法的結果不是整數,函式會將除法的值四捨五入為最接近的整數。
範例
範例 1 - 分割兩個整數
本範例文件說明如何使用 函 div() 式傳回兩個整數的除法。
# div.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Dividing integers
type: Microsoft.DSC.Debug/Echo
properties:
output: "[div(6,3)]"
dsc config get --file div.example.1.dsc.config.yaml config get
results:
- name: Dividing integers
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 2
messages: []
hadErrors: false
範例 2 - 分割巢狀函式的輸出
本範例文件說明如何使用 函 div() 式來分割巢狀組態函式的輸出。 因為輸出是 14 和 5,所以最終結果為 2。 DSC 會傳回不含餘數的完整整數值。 它不會將結果四捨五入到 3。
# div.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Dividing nested functions
type: Microsoft.DSC.Debug/Echo
properties:
output: "[div(mul(7,2), add(4,1))]"
dsc config get --file div.example.2.dsc.config.yaml
results:
- name: Dividing nested functions
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 2
messages: []
hadErrors: false
參數
運算元
函 div() 式預期只有兩個整數做為輸入。
操作數可以是整數或傳回整數之任何組態函式的輸出。 函式會將第一個操作數除以第二個操作數。 以逗號分隔 操作數 (,) 。
Type: integer
Required: true
MinimumCount: 2
MaximumCount: 2
輸出
函 div() 式會傳回整數值,代表第一個操作數與第二個操作數的除法。 如果除法結果不是整數,函式會傳回結果的整數值,而不會傳回小數餘數。
Type: integer