Hi! I want to get the result of a calculation (number) with this formula: ( ( Value from Custom State - 1 ) * Value of input field ) + 1
That is a seemingly simple math expression with brackets, but I don’t understand how to solve this with “variable” queries (custom state and input field are also in number format)
As you can see from the screenshot, I’m stuck on forming the first expression with brackets… Then I can’t add something else after the closing bracket (there is a multiplication sign “*”, but as a result it is perceived as a text character, not as an operator) Can someone help me, suggest me, maybe I’m doing something wrong?
You have to pick the math operands (+ - * /) from the drop-down list or they will be perceived as text. You have to type or use drop-downs in each Click field from left to right or you confuse the Bubble editor. Somehow, you skipped over a “Click” field and kept typing.
Or I might not understand you correctly. With dynamic fields like this, sometimes we have to delete everything and try two or three more times from scratch before things will finally fall into place.
Although at first I was able to find a math operator (the first screen shows “…-1”, but as soon as I put the expression in brackets, I can’t add another math operator after the brackets.
That, I don’t know. (The parentheses in Bubble are still in beta and could have bugs. I tend to avoid beta tests and haven’t tried them.) You could open a Bubble support ticket with that issue.
Fortunately, if I understand correctly, Bubble tends to do everything from left to right (not the usual: multiplication before addition, etc.), and with the way your formula is written, you might get the right results even with no parentheses.
Worst case scenario: You could do the computation in a front-end workflow, calculating the CustomState’s Value - 1 in the first step, and using the results of step 1 * Input’s Value in the second, and the results of the second step + 1 in the third, and put the results in another custom state which you would then display in your text field. We do a lot of workarounds in Bubble.
Yes, you’re quite right, I’ve read similar problems in other threads and found that Bubble does successive “calculations” from left to right, disregarding math rules (if I try to apply them) and disregarding round brackets. So, I’m lucky and the right calculations are done just right. But this is only in this case, unfortunately. If you need, for example, to calculate the expression 16 / (8-2), the Bubble will give the answer “0” instead of “4”, because it will do 16 / 8 and then subtract “2” from the result.
I also found a plugin Toolbox, there in the expression builder you can enter expressions, even with “white” brackets and it will be solved correctly, according to the mathematical rules. The main thing is to specify the output option “number”, and then the expression will be taken as a numeric formula, not as text. At least that’s how I tested it and I was able to display the correct result (maybe I got lucky again…).
this is really worst, I wish I could use simpler solutions for these options. After all, it makes sense…
Yes, in this case you will probably have to use third party plugins, one of them I noted above is Toolbox. But you write about a math plugin, could you please tell me what kind of plugin it is and how to find it?
Apparently you are free typing the parenthesis instead use the option that allow expressions create them automatically based on how you write the expression.
So, turn on the Experimental Parenthesis feature (Experimental for years now). You can do this at Settings > Versions tab.
Oh my God! You just opened my eyes! This is what I needed, I created a new project in a new account for my client and completely forgot about this experimental feature! I’m sitting here wondering why brackets don’t work - they worked before (in another account)? Thank you, you’ve shown me the right way in time!
WAIT - are you saying there is the ability to manually type in parentheses? I’ve always been trying to use the beta ones that “appear”, and then you need to be careful about where you click “More” for your next item to appear.
FWIW, you can do some advanced calculation order using native Bubble functionality and no parentheses by using Arbitrary Text a few times. For instance, in your original example, you could have the expression be: Arbitrary Text:convertedtonumber + 1, with the expression in Arbitrary text being: Arbitrary Text:convertedtonumber * Value of input field, with the value of this nested Arbitrary Text being: Value from Custom State - 1
Let me know if that doesn’t make sense. It’s not really a great solution for VERY complicated math, and you can’t see the end-to-end calculation all at once, but it IS a native solution for forcing calculation order of operations.
Thanks for another idea, if I get a chance to test this I will share the results. So far I’ve settled on the solution given to me by the users above. But your idea, I think, also has a right to life!