共用方式為


int

概要

從輸入字串或整數傳回整數。

語法

int(<inputValue>)

描述

int() 函式會傳回整數,將輸入字串轉換成整數。 如果您傳遞整數,則會傳回整數。 如果您傳遞任何其他值,包括非整數數位,則函式會引發無效的輸入錯誤。

例子

範例 1 - 從字串建立整數

此組態會傳回整數,將字串值 '4.7' 轉換為 4

# int.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo integer value
  type: Microsoft.DSC.Debug/Echo
  properties:
    output: "[int('4.7')]"
dsc config get --file int.example.1.dsc.config.yaml config get
results:
- name: Echo integer value of '4.7'
  type: Microsoft.DSC.Debug/Echo
  result:
    actualState:
      output: 4
messages: []
hadErrors: false

參數

inputValue

int() 函式預期輸入為字串或整數。 如果值是無法剖析為數位 DSC 的字串,則會傳回函式的錯誤。 如果值不是字串或整數,DSC 會傳回函式的無效輸入錯誤。

Type:         [String, Integer]
Required:     true
MinimumCount: 1
MaximumCount: 1

輸出

int() 函式會傳回輸入的整數表示法。 如果輸入值是具有小數部分的字串或數位,則函式會傳回沒有小數部分的整數。 它不會四捨五入,因此對於 4.999 的輸入值,函式會傳回 4

Type: integer