I have a formula which calculates a certain type of profit based on following parameters:
margin = 14.4;
Profit = FirstPrice - ((FirstPrice/100)* margin + 0.3) - SecondPrice;
Now let's suppose the calculated profit is: $3.92$, FirstPrice = 40 and SecondPrice = 30.
How can I now calculate the FirstPrice by modifying the Profit and by increasing it or lowering it ?
If I wanna say profit must be $2.5$, how would I then calculate the FirstPrice ?
Your formula, in mathematical notation, is:
$$ X = P_{1} - (\frac{P_{1}}{100}*m + 0.3) - P_{2}$$ where $X$ is profit, $P_{1}$ and $P_{2}$ are first and second price, and $m$ is margin.
$X$, the profit, is the subject of the formula, because it's all on its own on one side while all the other parameters are on the other. What you want to do is make $P_{1}$ the subject. To do this, you first need to group all the terms involving $P_{1}$ together. These terms are $P_{1}$ and $-\frac{P_{1}m}{100}$ (the minus sign is important), and when you divide each by $P_{1}$ you get $1$ and $-\frac{m}{100}$ respectively. So you can rewrite your formula as:
$$X = P_{1}\left(1 - \frac{m}{100}\right) - 0.3 - P_{2}$$
Now you add $P_{2}$ and $0.3$ to both sides so the term involving $P_{1}$ is on its own (note I've swapped the two sides of the formula):
$$ P_{1}\left(1-\frac{m}{100}\right) = X + P_{2} + 0.3$$
Now you've got $P_{1}$ times $\left(1-\frac{m}{100}\right)$ on one side, so just divide both sides by $\left(1-\frac{m}{100}\right)$:
$$ P_{1} = \frac{(X + P_{2} + 0.3)}{\left(1 - \frac{m}{100}\right)}$$
Or, in code: