What is the correct way to calculate a selling price from margin and a cost?
The "margin" is a portion of the selling price. It is defined as

$$\text {margin} \equiv \frac {P-C}{P}$$

From the above definition, we see that the margin cannot exceed $100\%$.

If one has the cost and he wants to calculate the price in order to have a specific margin, one must calculate

$$P(\text {margin}^*) = \frac {C}{1-\text {margin}^*}$$

The first formula written in the question is wrong, because it uses "margin", but it would become correct if instead one used the concept of "markup".

The "markup" is defined as the percentage increase of cost in order to determine the selling price:

$$\text {markup} \equiv \frac {P-C}{C}$$

It is easy to obtain that the relation between them is

$$\text {margin} = \frac {\text {markup}}{1+\text {markup}}$$