次の方法で共有


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