Using powershell I read in a text file that contains the check amount. I then create a query and get the amount due. The problem comes in because buyer could have multiple balances for different products. So they could write a check that covered A but not B and C.

$remainAmount = $currentAmount[0] - $checkAmount

How can I do this and not produce a negative number, force it to stop subtracting when zero is reached?

有帮助吗?

解决方案

One solution would be to use the [Math]::Max() function like this:

$remainamount = [Math]::Max($currentamount[0] - $checkamount,0)

That will give you the higher of the two numbers, so if they still owe something it gives that, or it gives 0.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top