質問

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