Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top