Reputation: 1718
With Powershell, is there a function to set a negative number to zero?
Or is this it?
If ($num -lt 0) {$num = 0}
Upvotes: 3
Views: 1479
Reputation: 439228
In case you're looking for a more concise way:
$num = [math]::max(0, $num)
A PowerShell (Core) 7+ alternative, using the ternary conditional operator:
$num = $num -lt 0 ? 0 : $num
Upvotes: 12