Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Synopsis
Returns an integer from an input string or integer.
Syntax
int(<inputValue>)
Description
The int()
function returns an integer, converting an input string into an integer. If you pass an
integer, it returns the integer. If you pass any other value, including a non-integer number, the
function raises an invalid input error.
Examples
Example 1 - Create an integer from a string
This configuration returns an integer, converting the string value '4.7'
to 4
.
# int.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo integer value
type: Test/Echo
properties:
output: "[int('4.7')]"
dsc config get --document int.example.1.dsc.config.yaml config get
results:
- name: Echo integer value of '4.7'
type: Test/Echo
result:
actualState:
output: 4
messages: []
hadErrors: false
Parameters
inputValue
The int()
function expects input as either a string or an integer. If the value is a string that
can't be parsed as a number DSC returns an error for the function. If the value isn't a string or
integer, DSC returns an invalid input error for the function.
Type: [String, Integer]
Required: true
MinimumCount: 1
MaximumCount: 1
Output
The int()
function returns an integer representation of the input. If the input value is a string
or number with a fractional part, the function returns the integer without the fractional part. It
doesn't round up, so for an input value of 4.999
the function returns 4
.
Type: integer