Can't wrap my head around simple math operations in bubble

I’m struggling to perform basic math operations in bubble and it’s driving me mad. All I want to do is take 3 inputs, calculate a value, and write it to a field. I’ve tried everything from math.js calls to math while creating a thing and I can’t get it done. The equation is pretty simple: split = 500 * (time/distance). Split is the result, time and distance are inputs. Breaking it down a bit more I am taking hours and minutes as inputs, then converting hours to minutes and back again with a remainder function. The problem I’m having is that I can’t figure out how to get the calculation to run in a workflow, and math.js local doesn’t seem to work, nor does a math.js call on a create thing, and I can’t get it to work. It feels like basic math operations shouldn’t be so convoluted, but they are, or I’m missing something. So, what am I missing? If I send this formula directly to math.js without bubble my result is simple and correct, how do I accomplish this in bubble?

Hi @jason8 , you can perform calculation on Input’s value and multiple 500 at the end on text field or you could try expression property of Toolbox Plugin | Bubble.
Let me know if this helps!

Ooo this is cool, is there a list of expression operators available? For example, split is a time value, so I convert to seconds, then perform the calculation, then covert to minutes and seconds using a remainder function in math.js. How can I accomplish the split=500*(time/distance) calculation using toolbox?

Have you tried time /distance*500?

Yes. What I’m struggling with is getting a time value out of the expression. If math.js, I was using a round and a remainder function to get minutes and seconds. I can’t seem to calculate time directly, so the order of operations is:

1. Convert minutes to seconds
2. Run expression on seconds
3. divide result by 60 to get minutes
4. Get remainder of previous operation to get seconds

The remainder function works in toolbox but I can’t get round to work.

There is a free plugin for converting time units, can’t remember the name now but I recall it wasn’t much used. Used it the other day to do time math and it works fine. If you can’t find it pm me and I’ll give you the name in about 8 hours.

So what I’ve done for now is use math.js to perform the rounding operation to get the minutes value out of the equation. It’s not the best or cleanest solution. Bubble really needs to add more math operations!

2 Likes

UPDATE: I found rounding and floor functions at the bottom of the list, not sure how I missed them before!

Hiya, Yesterday I had everything working and today I’m getting this error:

``````The plugin Toolbox / element Expression threw the following error: SyntaxError: Unexpected token '%'
at eval (PLUGIN_1488796042609x768734193128308700/Toolbox-update--Expression-.js:3:73)
at https://dhtiece9044ep.cloudfront.net/package/run_debug_js/581f46f1406d093f97e9927c382f3f77c205c7c0bea583ed4b12a9131befbc30/xfalse/x10:6:2311207 (please report this to the plugin author)``````

Hi @jason8, sorry I’m not sure what’s cause of this bug.