Help.. How to change 1 input fields math from going Negative,

Thanks in advance if you can help out on this simple math issue I am having. Probably something i’m just not seeing.

I have 1 issue here on my shopping cart I cannot figure out. To start

This is all working correctly.

When they apply some of their account balance to the deal the math all maths. (please not the account balance starts out at 15k just automatically changes.)

But…

when you apply more than the total owed, it will show a negative amount.

So I need to figure this one thing.

  1. How to stop them on the “would you like to apply” from putting more than the total cart price and the cart price going negative.

I have tried and google every which way I can, just not the one that works obviously.


,

How can I add that?
I would be forever grateful if someone could clear this up for me.

Thanks.

There is a <-max-> operator you can use that will output the maximum between the left side and the right side.
You can use Input value <-max-> 0 to make sure the number is never negative.

But you could also use conditionals in a workflow - these conditionals will check whether the balance is greater than the cart - and then the actions will proceed accordingly.

Are you having problems setting up the workflows? Or is it just a matter of not displaying the negative number?

1 Like

Thanks a million for answering,

I think The workflows will work fine, if I get it to where they cannot put in an over balance from their account.

I cannot seem to find how to add <-max-> 0 to that input field for it to work… Where does that go?

The max operator is only available on numbers - your input value is set to text so you have to keep using the :converted to number operator before using the max operator

1 Like

Thanks again.

I think I am getting closer, but now the total will just say 0. which is fine if they take it all form their account balance.

But then heir account balance is going down by the full amount,

So maybe i’m thinking about this the wrong way, how do you limit it to where they cant put in more than than the total cart price which is input 7???

Heres what I have now,



.

Ok, Ok, im closer. so now it auto fills the $380 total and minus it from their available balance. Problem still is if they add a zero accidently to the end, their account balance will reflect 3800. How do you hard cap the number they can add to the amount in input 7.

You can change the content type of the input to number - this will allow you to definte minimum and maximum values that the input will accept, anything outside of that will be invalid.

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.