Percentage function in PHP

Asked

Viewed 2,342 times

2

How to do a percentage function. In which it calculates the td or is the equal table of Excel to give the percentage.

I want to calculate the percentage of a value in PHP, for example 10% of 100, like Excel DADOSx100=% and calculate the tables in PDO.

2 answers

6

Considering what you said in your question comment would look like this:

$valor = 100; // valor total
$porcent = 10 / 100; // 10%

$resultado = $porcent * $valor;

echo "10% de 100 é: " .
$resultado;

1


$valor = 100; // valor total
$porcent = 50;
$totalporcent = 100;
$total = $porcent / $totalporcent;

$resultado = $total * $valor;

echo $porcent . "% de " . $totalporcent ." é: " .
$resultado;

//é igual ao de cima, mas achei melhor explicar um pouco melhor kkk

Browser other questions tagged

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