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

**URL:** <https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193>\
**Category:** APIs\
**Created:** [November 29, 2021, 1:11am UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193 "2021-11-29T01:11:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [November 29, 2021, 1:11am UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/1 "2021-11-29T01:11:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Vizard](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/vizard/32/99972_2.png) [@Vizard](https://forum.bubble.io/u/Vizard)\
**Post date:** [November 29, 2021, 5:03pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/2 "2021-11-29T17:03:00Z")

</div>

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](https://bubble.io/plugin/toolbox-1488796042609x768734193128308700).  
Let me know if this helps!

---

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [December 2, 2021, 6:35pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/3 "2021-12-02T18:35:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dehacked79](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/dehacked79/32/42926_2.png) [@dehacked79](https://forum.bubble.io/u/dehacked79)\
**Post date:** [December 2, 2021, 6:39pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/4 "2021-12-02T18:39:16Z")

</div>

Have you tried time /distance\*500?

---

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [December 2, 2021, 6:55pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/5 "2021-12-02T18:55:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dehacked79](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/dehacked79/32/42926_2.png) [@dehacked79](https://forum.bubble.io/u/dehacked79)\
**Post date:** [December 2, 2021, 7:00pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/6 "2021-12-02T19:00:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [December 2, 2021, 7:22pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/7 "2021-12-02T19:22:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [December 2, 2021, 7:53pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/8 "2021-12-02T19:53:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason8](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jason8](https://forum.bubble.io/u/jason8)\
**Post date:** [December 3, 2021, 9:41pm UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/9 "2021-12-03T21:41:35Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![Vizard](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/vizard/32/99972_2.png) [@Vizard](https://forum.bubble.io/u/Vizard)\
**Post date:** [December 4, 2021, 2:20am UTC](https://forum.bubble.io/t/cant-wrap-my-head-around-simple-math-operations-in-bubble/180193/10 "2021-12-04T02:20:56Z")

</div>

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