Account Balance Input is how much they have in their wallet available to be used for purchases.
Total Cart Price is the cost of goods in their cart, needing to be paid for.
Would like to Apply All or Part of Your Balance is the amount from their ‘wallet’ they would like to use to pay for the goods in their cart.
Total Owed is the difference between the total cost of goods in the cart and the amount from their wallet to apply to the purchase.
Your new account Balance is their account balance, less the amount of their balance to be used to pay for the cost of goods in their cart.
First, you should make it so for a UI/UX, you do not have the long title of ‘would like to apply all or part of your balance’…instead make a checkbox that states, ‘pay all from current balance’. When that is checked, you keep the input disabled, and set initial content to the total cart price value, conditionally on whether their account balance is greater than the total cart price. Also, set it conditionally to the total account balance if it is less than the total cart price. This can be done with one expression as below.
Account balance input value is greater than or equal to total cart input value: formatted as text - Yes (total cart price input value) No (account balance input value): converted to number)
This expression can just be the dynamic expression for the initial content of the input for ‘amount to apply from balance’.
If the checkbox is unchecked, then make the apply part of balance input enabled and allow the user to enter a value. Set the maximum value to be equal to account balance or total cart balance conditionally using the same expression above with the formatted as text and convert to number operators. This way they can never enter an amount that is greater than cart price or their account balance. Set minimum value of input to be 0.
Then your total owed can have initial content of cart price input value minus apply part of balance input value.
Finally, your new accunt balance initial content is the account balance input value minus the apply part of balance input value.
Always keep new account balance input disabled, as well as account balance and total cart price inputs.
If you set it up as I’ve explained, you don’t need to worry about negative numbers at all since the math will always be correct and the minimum values of the relevant inputs won’t allow for negative numbers to be applied by a user.