Percentage calculation [closed]

-3

In my online store I have the following option ex: from 1,119.00 to 999.00 the current price and the discount price, how can I know how many percent the person is saving with the purchase? How many percent of the discount does the purchase have? using the old value field and new value, embrace

    
asked by anonymous 12.01.2018 / 13:57

1 answer

1

I use the following form:

(V2-V1)/V1 × 100 = PORCENTAGEM

Let's say you have an item that has the value of $ 50 and with the discount stayed $ 20 so we put it as follows:

((20 – 50)/50) × 100 = PORCENTAGEM

(-30/50) × 100 = PORCENTAGEM

-0,60 × 100 = -60%

In PHP:

$valorAntigo = 50;
$valorNovo   = 20;

$Porcentagem = (($valorNovo - $valorAntigo)/$valorAntigo)*100;
    
12.01.2018 / 14:04