div

摘要

返回两个整数的除法的商。

语法

div(<operands>)

说明

函数 div() 返回两个整数除法的商。 如果除法的结果不是整数,则函数返回向下舍入为最接近整数的除法值。

示例

示例 1 - 除以两个整数

此示例文档演示如何使用 div() 函数返回两个整数的除法。

# div.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Dividing integers
  type: Test/Echo
  properties:
    output: "[div(6,3)]"
dsc config get --document div.example.1.dsc.config.yaml config get
results:
- name: Dividing integers
  type: Test/Echo
  result:
    actualState:
      output: 2
messages: []
hadErrors: false

示例 2 - 划分嵌套函数的输出

此示例文档演示如何使用 div() 函数来划分嵌套配置函数的输出。 由于输出为 14 和 5,因此最终结果为 2。 DSC 返回不带余数的完整整数值。 它不会将结果舍入到 3。

# div.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Dividing nested functions
  type: Test/Echo
  properties:
    output: "[div(mul(7,2), add(4,1))]"
dsc config get --document div.example.2.dsc.config.yaml
results:
- name: Dividing nested functions
  type: Test/Echo
  result:
    actualState:
      output: 2
messages: []
hadErrors: false

参数

操作数

函数 div() 需要恰好两个整数作为输入。 操作数可以是整数,也可以是返回整数的任何配置函数的输出。 函数将第一个操作数除以第二个操作数。 使用逗号 () , 分隔操作数。

Type:         integer
Required:     true
MinimumCount: 2
MaximumCount: 2

输出

函数 div() 返回一个整数值,表示第一个操作数与第二个操作数的除数。 如果除法结果不是整数,则函数返回结果的整数值,而不返回小数余数。

Type: integer