Whenever something works outside a function, but does not work inside the function, look at how you are calling the function and the type/value of the passed parameters.
In this case, part of the problem is the way you are calling the function in the Write-Host line. By putting the parameters inside parens and separating them with commas, you are telling PowerShell that those two values are a 2 element array of integers, and should be passed to the 1st parameter. Since you did not declare the type of your variables in the function, that was accepted, and your 2nd parameter remains empty.
I've added two Write-Host statements for you to see the values of your parameter variables after they are passed, and a "right" and "wrong" way of calling the function.
function Resolution2AspectRatio($Width, $Height) {
Write-Host "Width = $Width"
Write-Host "Height = $Height"
$tmp = $Width / $Height
return $tmp
}
[System.Windows.Forms.Screen]::AllScreens | Select Bounds, Primary | ForEach-Object {
$DisplayWidth = [int]$_.Bounds.Width
$DisplayHeight = [int]$_.Bounds.Height
Write-Host $($DisplayWidth/$DisplayHeight)
#Wrong way to call function
Write-Host $(Resolution2AspectRatio($DisplayWidth,$DisplayHeight))
#Right way to call function
Write-Host $(Resolution2AspectRatio $DisplayWidth $DisplayHeight)
}