Show profit or loss in negative percentage

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 revenue or expenditure is zero the calculation is wrong because it will be dividing by zero. Is there any way to calculate? For example, if we consider that I had 0,00 revenue and 300,00 expenditure it will have -100% profit margin.

    
asked by anonymous 07.03.2016 / 00:40

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 revenue is equal to zero, the formula can be modified to:

100 * ($receitas / $despesas) - 100

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

    
07.03.2016 / 03:04