# Calculating a sale price in bubble

Hello all.

I am trying to solve a (seemingly) simple thing in Bubble.

Let’s say I want to sell my watch for €1,000 via an online platform. The platform through which I offer the watch automatically deducts a commission from the sale price (e.g. 10%). How can I calculate the final selling price in Bubble?
As far as I understand it, I need many iteration loops to get close to the selling price.

I have implemented this on a test basis with 3 iteration loops. But it seems to me to be solved very cumbersome. And with a higher commission you would need more and more iterations.
Surely something like this can be solved much easier and more elegant, right?

This is my attempt:

And in the editor:

Thank you

Here is how I would implement this (it may not be the best way).

If we know that we want to make \$1000, with a dealers margin of 10%, then we know that the profit is 90% of the selling price (100% - dealers margin).

With that in mind, we can take the profit, divide it by 90 to get 1% and then multiply it by 100 to get the sell price.

In any case, if you deduct the dealers margin from 100, and then divide the desired profit margin into the resulting number, then multiply it by 100, it should give you the right number.

Here is another example:
Desired profit = \$200
Dealers margin = 7%
Desired profit as a % of sell price = 93% (100%-7%)
1% of sell price = approximately \$2.15 (Desired profit / desired profit as a % of sell price)
Sell price = \$215.05 (1% of sell price * 100)

Given it still contains a few calculations that you may struggle to put into a single formula, you might want to store the result of some calculations (100% - dealers margin % for example) in an element’s state and then refer back to it in your main calculation.

1 Like

Wow. Thank you very much! That is definitely THE perfect solution.

I was so convinced that it was complicated to calculate the number that I didn’t realize that the solution was actually so simple.

(but then again math has never been my strong point)

Thanks again. Works perfect.

1 Like