Introduction
Integer and floating-point types let you work with whole numbers and numbers with decimals in your scripts.
# Integer example $wholeNumber = 10 # Floating-point example $decimalNumber = 3.14
$age = 25 $pi = 3.14159
$count = [int]100 $price = [double]19.99
$result = 5 / 2 Write-Output $result
$wholeNumber = 7 $floatingNumber = 2.5 $sum = $wholeNumber + $floatingNumber Write-Output "Whole number: $wholeNumber" Write-Output "Floating number: $floatingNumber" Write-Output "Sum: $sum"
$a = 7
$b = 2
$c = $a / $b
Write-Output $c
$x = 10
$y = 3.5
$z = [int]$x / $y
Write-Output $z
$avg = ([int](4 + 7 + 10)) / 3casts sum to int (already int), division by int 3 gives integer division result truncated.
Write-Output $avg
$avg = [int](4 + 7 + 10 / 3)casts after dividing 10 by 3, changing order and result.
Write-Output $avg
$avg = (4 + 7 + 10) / [int]3divides by int 3, integer division.
Write-Output $avg
$avg = (4 + 7 + 10) / 3.0divides by 3.0, ensuring float result.
Write-Output $avg
Pass the test and this pattern moves unknown