PowerShell - Variables and Data Types
You want to calculate the average of three numbers: 4, 7, and 10 in PowerShell, ensuring the result is a floating-point number. Which script correctly does this?
$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
15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions