Show profit or loss in negative percentage

Asked

Viewed 1,992 times

0

Considering the following data:

$despesas = 2000;
$receitas = 100;
$lucroprejuizo = ($receitas - $despesas) / $receitas)*100;

I have a result of: -1900%

But if any of the variable revenues or expenses is zero the wrong calculation because it is dividing by zero. Is there any way to calculate? For example if you consider that I had 0,00 of revenue and 300,00 of expenses he will have -100% profiteering.

  • 1

    It is incorrect to say that you had 100% prejudice to a value ranging from 0 to 300 (and negative loss, so, not even talk). The problem is not in mathematics, but in concepts. I would suggest rethinking logic, based on the practical use of information, first of all.

  • 1

    I agree with @Bacco, logic needs to be rethought. In addition to what he said, also note that if you have a value of 100 receipts and 50 expenses, your $lucroprejuizo variable will give you 50% profit, when in fact the profit is 100%.

  • Thank you all. @monosan some suggestion so in this your example to return me the correct profit?

  • Yes, @mcasite. Split by expenses instead of split by revenues.

  • @monosan and yet, it gets complicated. Profit is absolute, not relative. If I have 200 of expense and 300 of revenue, or if I have 400 of expense and 500 of revenue, the profit is the same, but the percentage changes It may even be that the author wants a "profit on the movement", but there is a good chance that is not what someone will need in practice..

  • @Bacco, it is, the correct terminology I do not know what it is. But he wants the value in percentage, be it profit or whatever the most appropriate name.

  • 1

    @monosan I have my doubts if what he asked for is in fact what he wants, which way, if that’s it, the epx response solves. I just think it’s important for the author to be aware of the problem (and we’ve done this, now it’s up to him).

Show 2 more comments

1 answer

1

The case of $expense = 0 you would have to filter with an "if" condition because it represents an infinite profit (revenue without any expense). To eliminate division by zero when the recipe is equal to zero, the formula can be modified to:

100 * ($receitas / $despesas) - 100

In this formula, if revenue=300 and expense=250, the result is +20 (20% profit). If revenue=0 and expense is different from zero, the result is always -100%.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.